1、獲取總列數 int Column_num = DataGridView1.ColumnCount; 2、獲取總行數 int Column_num = DataGridView1.RowCount; 3、獲取選中行索引 int selectRows_num = DataGridView1.Curr ...
1、獲取總列數
int Column_num = DataGridView1.ColumnCount;
2、獲取總行數
int Column_num = DataGridView1.RowCount;
3、獲取選中行索引
int selectRows_num = DataGridView1.CurrentRow.Index;
4、獲取選中行的全部數據
list<string> Data = new list<string>();
for(int i =0;i<Column_num ;i++)
{
Data.Add(DataGridView1.Rows[selectRoes_num].Cells[i].Value.Tostring());
}
5、獲取某一列的所有的值
List<string> Data = new List<string>();
for(int i =0;i<DataGridView1.Rows.Count;i++)
{
Data.Add(DataGridView1.Rows[i].Cells[1].Value.Tostring())
}
6、獲取表頭
List<string> Head = new List<string>();
int Column_num = Tablebase_ADD.ColumnCount;//獲取數據表列數
for (int i = 0; i < Column_num; i++)
{
Head.Add(DaTaGridView1.Columns[i].HeaderCell.Value.ToString());
}