using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace _2_DataGridView绑定数据源
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dgvbindMode.DataSource = BindModSource().Tables[0];
dgvNonbindMode.DataSource = NonBindSource();
}
private DataSet BindModSource() //绑定模式,有线程数据库
{
string constr = "Server=.;user=sa;pwd=darly;database=csharpzx";
SqlConnection mycon = new SqlConnection(constr);
DataSet myds = new DataSet();
try
{
mycon.Open();
string sql = "select name,gender from mytable";
SqlDataAdapter myda = new SqlDataAdapter(sql, mycon);
myda.Fill(myds, "mytable");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "错误提示");
}
finally
{
mycon.Close();
}
return myds;
}
private DataTable NonBindSource() //非绑定模式,没有数据库
{
DataTable mydt = new DataTable();
mydt.Columns.Add("name", Type.GetType("System.String"));
mydt.Columns.Add("gender", Type.GetType("System.String"));
string[,] mystr = { { "张三", "女" }, { "李四", "女" }, { "王五", "女" }, { "赵六", "女" }, { "张祺", "女" }};
for (int i = 0; i < mystr.Length / 2; i++)
{
DataRow myRow = mydt.NewRow();
myRow[0] = mystr[i, 0];
myRow[1] = mystr[i, 1];
mydt.Rows.Add(myRow);
}
return mydt;
}
}
}
实例,当点击单元格时获取到点击的是第几行第几列,并获取单元格内的值
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _3_获取单元格
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“csharpzxDataSet1.mytable”中。您可以根据需要移动或删除它。
this.mytableTableAdapter.Fill(this.csharpzxDataSet1.mytable);
}
//方法的定义中第一个参数 sender就是指的当前操作的控件,第二个参数就是用于返回当前操作控件内容值
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
//获取行列索引
//1种方式
//int row = e.RowIndex + 1; //获取的行数;
//int col = e.ColumnIndex + 1; //获取列数
//MessageBox.Show("你点击的是:第" + row.ToString() + "行,第" + col.ToString() + "列。");
//第2中方式
//int row2 = dataGridView1.CurrentCell.RowIndex + 1;
//int col2 = dataGridView1.CurrentCell.ColumnIndex + 1;
//MessageBox.Show("你点击的是:第" + row2.ToString() + "行,第" + col2.ToString() + "列。");
//第3中方式
//int row3 = dataGridView1.CurrentCellAddress.Y + 1;
int col3 = dataGridView1.CurrentCellAddress.X + 1;
//MessageBox.Show("你点击的是:第" + row3.ToString() + "行,第" + col3.ToString() + "列。");
//第四种方式
int row4 = dataGridView1.CurrentRow.Index + 1; //此方法仅适用于行,不适用于列。
//获取单元格内容Value
//第一种方式
//string cell = dataGridView1.Rows[row4-1].Cells[col3-1].Value.ToString();
//第二种方式
string cell = dataGridView1.CurrentCell.Value.ToString();
MessageBox.Show("你点击的是:第" + row4.ToString() + "行,第" + col3.ToString() + "列。\n内容是:"+cell);
}
}
}
隐藏与显示
visible: true为显示,false为隐藏
Rows:行
Columns:列
using System;
using System.Windows.Forms;
namespace _4_DataGridView隐藏与显示行和列
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“csharpzxDataSet.mytable”中。您可以根据需要移动或删除它。
this.mytableTableAdapter.Fill(this.csharpzxDataSet.mytable);
}
private void button1_Click(object sender, EventArgs e)
{
string mystr = button1.Text;
if (mystr.Contains("隐藏"))
{
//获取单元格所在的列
//int col = dataGridView1.CurrentCell.ColumnIndex;
dataGridView1.Columns[4].Visible = false;
button1.Text = "显示部门列";
}
else
{
dataGridView1.Columns[4].Visible = true;
button1.Text = "隐藏部门列";
}
}
private void button2_Click(object sender, EventArgs e)
{
string mystr = button2.Text;
if (mystr.Contains("隐藏"))
{
dataGridView1.Rows[1].Visible = false;
button2.Text = "显示张三行";
}
else
{
dataGridView1.Rows[1].Visible = true;
button2.Text = "隐藏张三行";
}
}
}
}
右键:ContextMenuStrip
删除行DataGridView1.Rows.RemoveAt(行索引值);
using System;
using System.Windows.Forms;
namespace DataGrideView右键删除行
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“csharpzxDataSet.mytable”中。您可以根据需要移动或删除它。
this.mytableTableAdapter.Fill(this.csharpzxDataSet.mytable);
}
private int rowIndex = 0;
private void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right) //判断鼠标操作事件,是左键还是右键
{
this.dataGridView1.Rows[e.RowIndex].Selected = true; //选中当前行
//如果没有下面命令,每次点击会累加选择,出现多条行记录被选中的情况,下面命令就是右击是定义那个单元格为当前单元格;
this.dataGridView1.CurrentCell = this.dataGridView1.Rows[e.RowIndex].Cells[0];
rowIndex = e.RowIndex; //将当前行的索引值赋值给公共变量,以便删除时判断是否为空行(新行)
//this.contextMenuStrip1.Show(this.dataGridView1, e.Location); //第一个参数是指定那个控件,第二个参数是当前事件发生的地方
this.contextMenuStrip1.Show(Cursor.Position); //鼠标点击出显示
}
}
private void 删除行ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!this.dataGridView1.Rows[rowIndex].IsNewRow)
{
this.dataGridView1.Rows.RemoveAt(rowIndex);
}
}
}
}
分类: Sort
筛选:通过声明DataView,更改DataSource,
using System;
using System.ComponentModel;
using System.Data;
using System.Windows.Forms;
namespace _6__DataGridView升序与筛选
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“csharpzxDataSet.mytable”中。您可以根据需要移动或删除它。
this.mytableTableAdapter.Fill(this.csharpzxDataSet.mytable);
}
private void button1_Click(object sender, EventArgs e)
{
dataGridView1.Sort(dataGridView1.Columns[3], ListSortDirection.Ascending); //第一个参数是按照哪一个列拍序,第二个参数是升序还是降序:Descending-降序,Ascending升序
}
private void button2_Click(object sender, EventArgs e)
{
//参数1源数据表,参数2筛选条件,参数3筛选后的排列方式,参数4当前行的状态(dataview的状态,指定为当前行的状态)
DataView dv = new DataView(this.csharpzxDataSet.mytable, "department='开发部'", "age Asc", DataViewRowState.CurrentRows);
//上面语句可以简单理解,将源数据进行筛选,下面的语句是将筛选出来的数据绑定到DataGridView中。
dataGridView1.DataSource = dv;
}
}
}
using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace _7_DataGridView直接修改数据
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private SqlConnection GeConnection()
{
string constr = "Server=.;user=sa;pwd=darly;database=csharpzx";
SqlConnection mycon = new SqlConnection(constr);
return mycon;
}
private void dgvBind()
{
SqlConnection mycon = GeConnection();
try
{
mycon.Open();
SqlDataAdapter sda =new SqlDataAdapter("select * from mytable", mycon);
DataTable table = new DataTable();
sda.Fill(table);
this.dataGridView1.AutoGenerateColumns = true; //设置DataGridView自动创建列
this.dataGridView1.DataSource = table;
this.dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
mycon.Close();
}
}
private void Form1_Load(object sender, EventArgs e)
{
dgvBind();
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
SqlConnection mycon = GeConnection();
try
{
mycon.Open();
string mystr1=dataGridView1.Columns[e.ColumnIndex].HeaderText+"="+"'"+dataGridView1.CurrentCell.Value.ToString()+"'"; //获取档前单元格的所在列的标头
string mystr2=dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
string updatsql = "update mytable set "+mystr1+" where id = "+mystr2;
MessageBox.Show(updatsql);
SqlCommand mycom = new SqlCommand(updatsql, mycon);
mycom.ExecuteNonQuery();
dgvBind();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
mycon.Close();
}
}
}
}
如果想让选中的DataGridView的行显示不同颜色,就要通过DataGridView控件RowPrePaint事件中重新设置所选的DefaultCellStyle属性来实现
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _8_DataGridView当前行显示不同的颜色
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“csharpzxDataSet.mytable”中。您可以根据需要移动或删除它。
this.mytableTableAdapter.Fill(this.csharpzxDataSet.mytable);
}
private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
if (e.RowIndex >= dataGridView1.Rows.Count - 1) return; //如果选中的行是一个新行(待添加内容)不进行操作,直接返回
Color oldForeColor = new Color();
Color oldBackColor = new Color();
// object是所有类的基类, var是可以是所有变量类型,不知道变量类型时,可以声明为var格式
var row = dataGridView1.Rows[e.RowIndex]; //操作的行
if (row == dataGridView1.CurrentRow) //判断操作行与当前行是不是一行,如果一样代表是首次操作,所以要绘制不同样式
{
if (row.DefaultCellStyle.ForeColor != Color.White) ;
{
oldForeColor = row.DefaultCellStyle.ForeColor; // 存储现在的前景色
row.DefaultCellStyle.ForeColor = Color.White; // 设置前景色为白色
}
if (row.DefaultCellStyle.BackColor != Color.Blue)
{
oldBackColor = row.DefaultCellStyle.BackColor;
row.DefaultCellStyle.BackColor = Color.Blue;
}
}
else
{
row.DefaultCellStyle.ForeColor = oldForeColor;
row.DefaultCellStyle.BackColor = oldBackColor;
}
}
}
}
绘制DataGridView的行序列号
RowPostPaint事件(当我们完成DataGridView绘制后执行的事件),通过Rectangle对象矩形区域,然后再通过TextRenderer的DrawText方法绘制序列号
Rectangle(x,y,width,height)
DrawText(IDeviceContext dc, text,font,Rectangle bounds, foreColor,TextFormatFlags) 第一个参数(IDeviceContext dc)是在哪个控件上进行绘制,Rectangle bounds矩形边界,TextFormatFlags字体对齐方式
using System;
using System.Drawing;
using System.Windows.Forms;
namespace _9_DataGridView添加行序号
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“csharpzxDataSet.mytable”中。您可以根据需要移动或删除它。
this.mytableTableAdapter.Fill(this.csharpzxDataSet.mytable);
}
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
//e代表DataGridView,RowBound控件行bianjie
Rectangle myrec = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, dataGridView1.RowHeadersWidth-5, e.RowBounds.Height); //宽度值减小是为了内容与下一列间隔开
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), dataGridView1.RowHeadersDefaultCellStyle.Font, myrec, dataGridView1.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}
}
}
两种方法:
第一种 DataGridView1.Rows[i].DefaultCellStyle.BAckColor
第二种:AlternatingRowsDefaultCellStyle属性,获取或这是应用于DataGridView的奇数行的默认单元格样式。RowsDefaultCellStyle属性获取或设置DataGridView的行单元格的默认样式
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _10_DataGridView各行显示不同的颜色
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“csharpzxDataSet.mytable”中。您可以根据需要移动或删除它。
this.mytableTableAdapter.Fill(this.csharpzxDataSet.mytable);
第一种方式
//for (int i=0; i
//{
// if (i % 2 == 0)
// this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Pink;
// else
// this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Violet;
//}
//第二种
this.dataGridView1.RowsDefaultCellStyle.BackColor = Color.Violet;
this.dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.SaddleBrown;
}
}
}
思路:将数据表整体填充值一个DataSet中,然后部分现实(DataAdapter Fill重载)
DataGridView
BindingNavigate
bindingSource:将DataGridView的数据源于BindingNavicat关联
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace _11_DataGridView分页显示
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private SqlDataAdapter pageDA;
private DataSet pageDS = new DataSet();
private int startval = 0; //起始值
private int valPerPage = 3;
private int toalValNumber; //总条数
private int currentPage = 1;
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.AllowUserToAddRows = false;
string constr = "Server=.;user=sa;pwd=darly;database=csharpzx";
SqlConnection mycon = new SqlConnection(constr);
try
{
mycon.Open();
string sql = "select * from mytable";
pageDA = new SqlDataAdapter(sql, mycon);
pageDA.Fill(pageDS, "mytable");
toalValNumber = pageDS.Tables[0].Rows.Count;
//总页数计算
int totalPageNumber = (toalValNumber % valPerPage == 0) ? (toalValNumber / valPerPage) : (toalValNumber / valPerPage + 1); //三目表达式
toolStripLabel1.Text = "/" + totalPageNumber;
LoadData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
mycon.Close();
}
}
private void LoadData()
{
currentPage = startval / valPerPage + 1; //计算初始当前页,初始值为0,故首次打开显示第一页数据
toolStripTextBox1.Text = currentPage.ToString();
pageDS.Clear(); //将数据集清空
pageDA.Fill(pageDS, startval, valPerPage, "mytable");
bindingSource1.DataSource = pageDS.Tables[0]; //bindingSource1绑定数据源
bindingNavigator1.BindingSource = bindingSource1; //bindingNavigator1绑定数据源
dataGridView1.DataSource = bindingSource1;
}
private void bindingNavigator1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
if (e.ClickedItem.Text == "上一页")
{
startval = startval - valPerPage;
if (startval < 0)
{
MessageBox.Show("已经是第一页");
startval = 0;
return;
}
}
if (e.ClickedItem.Text == "下一页")
{
startval = startval + valPerPage;
if(startval>toalValNumber)
{
MessageBox.Show("已经是最后一页");
startval = startval - valPerPage;
return;
}
}
LoadData();
}
}
}
在DataGridView单元各种,当输入指定字符时,自动完成填充
通过TExBox实现 TextBox有以下两个属性
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _13_DataGridView自动填充单元格
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“csharpzxDataSet.mytable”中。您可以根据需要移动或删除它。
this.mytableTableAdapter.Fill(this.csharpzxDataSet.mytable);
}
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
string titleText = dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].HeaderText;
if(titleText.Equals("department"))
{
TextBox autoText = e.Control as TextBox;
if(autoText !=null)
{
autoText.AutoCompleteMode = AutoCompleteMode.Suggest;
autoText.AutoCompleteSource = AutoCompleteSource.CustomSource;
AutoCompleteStringCollection dataCollection = new AutoCompleteStringCollection();
dataCollection.Add("开发部");
dataCollection.Add("技术部");
dataCollection.Add("测试部");
autoText.AutoCompleteCustomSource = dataCollection;
}
}
}
}
}
创建职员信息表:添加姓名、性别、工资
绘制行号,选中行显示为蓝色
其他行就显示不同颜色
分页显示
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace _14__任务实施
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int valToalNum = 500; //产生的总条数
DataTable dtable;
int valPerPage = 15; //每页条数
int pageNum = 0; //总页数
int pageCurrent = 1; //当前页序号
int valCurrent = 0; //当前条数
int valstartCurrent = 0; //当前页起始条数
int valEndIndex = 0; //当前页终止条数
private void dtGenerate() //数据产生方法
{
dtable = new DataTable("ClerkSalary");
dtable.Columns.Add("姓名", Type.GetType("System.String"));
dtable.Columns.Add("性别", Type.GetType("System.String"));
dtable.Columns.Add("工资", Type.GetType("System.Int32"));
String familyName = "赵钱孙李周吴郑王冯陈诸卫蒋沈崔胡刘";
string lastName = @"姓名汉语词语人的姓氏和名字名字是人类为区分个体给每
个人特定的名称符号是通过语言文字信息区别人群个体
差异的标志由于有了姓名人类才能正常有序地交往因此每个人都有一个属于自己的姓名";
string gender = "男女";
Random rd = new Random();
for (int i = 0; i < valToalNum; i++)
{
//增加行方式一
string name = familyName[rd.Next(0, familyName.Length)].ToString() + lastName[rd.Next(0, lastName.Length)].ToString() + lastName[rd.Next(0, lastName.Length)].ToString();
string Gender = gender[rd.Next(0, gender.Length)].ToString();
int salary = rd.Next(1800, 10000);
dtable.Rows.Add(new object[] { name, Gender, salary });
//增加行方式二
//DataRow dr = dtable.NewRow();
//dr[0] = familyName[rd.Next(0, familyName.Length)].ToString() + lastName[rd.Next(0, lastName.Length)].ToString() + lastName[rd.Next(0, lastName.Length)].ToString();
//dr[1] = gender[rd.Next(0, gender.Length)].ToString();
//dr[2] = rd.Next(1800, 1000);
//dtable.Rows.Add(dr);
}
}
private void loadData() //加载当前页的数据
{
DataTable dtTemp = dtable.Clone();
if (pageCurrent == pageNum) valEndIndex = valToalNum - 1; //只有一页
else valEndIndex = pageCurrent * valPerPage - 1; //不止一页
valstartCurrent = valCurrent;
toolStripTextBox1.Text = pageCurrent.ToString();
toolStripLabel1.Text = "/" + Convert.ToString(pageNum);
//从原数据表中读取当前数据
for (int i = valstartCurrent; i < valEndIndex; i++)
{
dtTemp.ImportRow(dtable.Rows[i]); //将响应航导入到临时表中
valCurrent++;
}
//绑定数据源
bindingSource1.DataSource = dtTemp;
bindingNavigator1.BindingSource = bindingSource1;
dataGridView1.DataSource = bindingSource1;
//奇偶行显示不同的颜色
dataGridView1.RowsDefaultCellStyle.BackColor = Color.Pink;
dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Violet;
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
dtGenerate();
//MessageBox.Show("数据生产完成");
pageNum = (valToalNum % valPerPage == 0) ? (valToalNum / valPerPage) : (valToalNum / valPerPage + 1);
loadData();
dataGridView1.ReadOnly = true;
dataGridView1.AllowUserToAddRows = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
Rectangle myrec = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, dataGridView1.RowHeadersWidth, e.RowBounds.Height);
//TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), dataGridView1.RowHeadersDefaultCellStyle.Font, myrec, dataGridView1.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1+valstartCurrent).ToString(), dataGridView1.RowHeadersDefaultCellStyle.Font, myrec, dataGridView1.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
if (e.RowIndex >= dataGridView1.Rows.Count - 1) return; //如果选中的行是一个新行(待添加内容)不进行操作,直接返回
Color oldForeColor = new Color();
Color oldBackColor = new Color();
// object是所有类的基类, var是可以是所有变量类型,不知道变量类型时,可以声明为var格式
var row = dataGridView1.Rows[e.RowIndex]; //操作的行
if (row == dataGridView1.CurrentRow) //判断操作行与当前行是不是一行,如果一样代表是首次操作,所以要绘制不同样式
{
if (row.DefaultCellStyle.ForeColor != Color.White)
{
oldForeColor = row.DefaultCellStyle.ForeColor; // 存储现在的前景色
row.DefaultCellStyle.ForeColor = Color.White; // 设置前景色为白色
}
if (row.DefaultCellStyle.BackColor != Color.Blue)
{
oldBackColor = row.DefaultCellStyle.BackColor;
row.DefaultCellStyle.BackColor = Color.Blue;
}
}
else
{
row.DefaultCellStyle.ForeColor = oldForeColor;
row.DefaultCellStyle.BackColor = oldBackColor;
}
}
private void bindingNavigator1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
if (e.ClickedItem.Text == "上一页")
{
pageCurrent--;
if (pageCurrent <= 0)
{
MessageBox.Show("已经是最后一页");
pageCurrent++;
return;
}
else
{
valCurrent = valPerPage * (pageCurrent - 1);
}
loadData();
}
if(e.ClickedItem.Text=="下一页")
{
pageCurrent++;
if(pageCurrent>pageNum)
{
pageCurrent--;
MessageBox.Show("已经是最后一页");
return;
}
else
{
valCurrent = valPerPage * (pageCurrent - 1);
}
loadData();
}
}
}
}