110,571
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication100
{
public partial class Form1 : Form
{
int PageIndex = 0;
DataGridView DGV = new DataGridView();
public Form1()
{
InitializeComponent();
DGV.Parent = this;
DataGridViewTextBoxColumn Column = new DataGridViewTextBoxColumn();
Column.HeaderText = "c1";
Column.Name = "c1";
Column.DataPropertyName = "c1";
DGV.Columns.Add(Column);
DGV.RowPrePaint += new DataGridViewRowPrePaintEventHandler(DGV_RowPrePaint);
DGV.DataSource = GetDateTable(PageIndex);
DGV.AllowUserToAddRows = false;
Button BtnPriorPage = new Button();
BtnPriorPage.Parent = this;
BtnPriorPage.Text = "上一页";
BtnPriorPage.Click += new EventHandler(BtnPriorPage_Click);
BtnPriorPage.Location = new Point(0, 200);
Button BtnNextPage = new Button();
BtnNextPage.Parent = this;
BtnNextPage.Text = "下一页";
BtnNextPage.Click += new EventHandler(BtnNextPage_Click);
BtnNextPage.Location = new Point(100, 200);
}
void BtnNextPage_Click(object sender, EventArgs e)
{
DGV.DataSource = GetDateTable(PageIndex + 1);
}
void BtnPriorPage_Click(object sender, EventArgs e)
{
DGV.DataSource = GetDateTable(PageIndex - 1);
}
DataTable GetDateTable(int NewPageIndex)
{
DataTable DT = new DataTable();
this.PageIndex = NewPageIndex < 0 ? 0 : NewPageIndex > 30 ? 30 : NewPageIndex;
DT.Columns.Add("c1", typeof(int));
for (int i = this.PageIndex * 3; i < (this.PageIndex + 1) * 3; i++)
DT.Rows.Add(new Object[] { i });
return DT;
}
void DGV_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
DataGridView DGV = (DataGridView)sender;
int i = Convert.ToInt32(DGV.Rows[e.RowIndex].Cells[0].Value) % 5;
switch (i)
{
case 0: DGV.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red; break;
case 1: DGV.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Green; break;
case 2: DGV.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Blue; break;
case 3: DGV.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Yellow; break;
case 4: DGV.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White; break;
}
}
}
}
foreach (DataGridViewRow row in dataGridView1.Rows)
{
int i = row.Index % 6;
#region 根据对方通话类型控制背景色
switch (i)
{
case 1:
row.DefaultCellStyle.BackColor = Color.Red;
break;
case 2:
row.DefaultCellStyle.BackColor = Color.Yellow;
break;
case 3:
row.DefaultCellStyle.BackColor = Color.Wheat;
break;
case 4:
row.DefaultCellStyle.BackColor = Color.YellowGreen;
break;
case 5:
row.DefaultCellStyle.BackColor = Color.Tomato;
break;
case 6:
row.DefaultCellStyle.BackColor = Color.SteelBlue;
break;
}
#endregion
}