(1)、获取DataGridView控件中的当前单元格
行索引:dataGridView1.CurrentCell.RowIndex.ToString();
列索引:dataGridView1.CurrentCell.ColumnIndex.ToString();
(2)、复制DataSet
DataSet ds_copy = ds.Copy(); //调用一个已经存在的数据集的Copy方法,返回值仍然是一个DataSet
dataGridView1.DataSource = ds_copy.Tables[0];
(3)、选中DataGridView控件中的行时显示不同颜色
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; //整行被选中
dataGridView1.ReadOnly = true; //DataGridView控件中的数据为只读,不能修改
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.YellowGreen; // 设置被选中行的背景颜色
(4)、禁止在DataGridView控件中添加和删除行
dataGridView1.AllowUserToAddRows = false; //属性设为false
dataGridView1.AllowUserToDeleteRows = false; //属性设为false
dataGridView1.ReadOnly = false; DataGridView控件
Datagridview
最新推荐文章于 2024-01-30 09:11:18 发布