我有一個CheckBox列的Datagrid。我需要從這個數據網格中選擇多行,並將SelectedRows獲取到另一個表單。我需要的是,當我檢查複選框時,所有選中的行必須仍然被選中(藍色高亮),直到我將它們傳遞給另一個表單。我現在能做到這一點,但只是一行,選擇一個與此代碼SelectRow與DataGridView中的複選框
private void button2_Click(object sender, EventArgs e)
{
DataTable table = new DataTable();
foreach (DataGridViewColumn column in dataGridView1.Columns)
{
table.Columns.Add(column.Name, typeof(string)); //tipo cell??
}
for (int i = 0; i < dataGridView1.SelectedRows.Count; i++)
{
table.Rows.Add();
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
table.Rows[i][j] = dataGridView1.SelectedRows[i].Cells[j].Value;
fph.dataGridView1.DataSource = table; //DATAGRID DO FORM PH
}
}
}
謝謝大家!
你有MultiSelect嗎? – TaW
您的應用程序中是否有DataGrid和DataGridView,或者只有DataGridView?如果是後一種情況,請避免將其縮短到DataGrid,因爲DataGrid是另一個(幾乎不贊成使用的).NET組件的名稱。 –
@TaW - 是的,我擁有它! – Reznor13