资 源 简 介
Visual C#显示选择的DataGridView单元格,获取DataGridView控件中选定的单元格、行和列,测试前请连接好数据库,实现此功能核心代码如下:
if (customersDataGridView.AreAllCellsSelected(true))
{
MessageBox.Show("所有单元格已经被选择!", "信息提示",MessageBoxButtons.OK);
}
else
{
System.Text.StringBuilder MyInfo =new System.Text.StringBuilder();
for (int i = 0;
i < MyCount; i++)
{
MyInfo.Append("行号: ");
MyInfo.Append(customersDataGridView.SelectedCells[i].RowIndex.ToString());
MyInfo.Append(", 列号: ");
MyInfo.Append(customersDataGridView.SelectedCells[i].ColumnIndex.ToString());
MyInfo.Append(", 单元格值: ");
MyInfo.Append(customersDataGridView.SelectedCells[i].Value.ToString());
MyInfo.Append(Environment.NewLine);
}
MyInfo.Append("一共选择了: " + MyCount.ToString()+"个单元格");
MessageBox.Show(MyInfo.ToString(), "信息提示", MessageBoxButtons.OK);
}