如何在 c# 中使用数据表禁用数据网格中的多选选项?实际上我有两个表 A 和 B 现在我要从表 A 中选择一个值,然后单击向下箭头按钮将所选行从表 A 移动到表 B
现在第一次,当我在表 A 中选择一行并单击向下箭头按钮时,选择的行无法添加,但是当我尝试相同的操作时,它工作正常..
这是我的代码片段——这是我第一次选择一行并单击向下箭头按钮时,它会弹出我 :: 未选择行!之后它完美地工作..
private void btnSelect_Click(object sender, EventArgs e)
{
dgvFormFieldsView.MultiSelect = false;
DataGridViewSelectedRowCollection selectedRows = dgvFormFieldsView.SelectedRows;
dgvFormFieldsView.ClearSelection();
if (selectedRows.Count == 0)
{
MessageBox.Show("No rows selected!", "Warning");
return;
}
for (int i = selectedRows.Count -1 ; i >= 0; i--)
{
string fieldLabel = null;
string fieldType = null;
string tabOrder = null;
tabOrder = (string)selectedRows[i].Cells[0].Value;
fieldLabel = (string)selectedRows[i].Cells[1].Value;
fieldType = (string)selectedRows[i].Cells[2].Value;
DataRow newRow = selectedFieldsTable.NewRow();
newRow["Field Name"] = fieldLabel;
newRow["Field Type"] = fieldType;
/*Temp Table*/
DataRow newRows = TempTable.NewRow();
newRows["Field Name"] = fieldLabel;
newRows["Field Type"] = fieldType;
if (!selectedFieldsTable.Rows.Contains(new System.Object[] { fieldType, fieldLabel }))
{
selectedFieldsTable.Rows.Add(newRow);
acc = selectedFieldsTable.Rows.Count;
temprow = TempTable.Rows.Count;
if (temprow < 5)
{
TempTable.Rows.Add(newRows);
//Console.WriteLine(counter);
currenttemptablecounter = currenttemptablecounter + 1;
Console.WriteLine(currenttemptablecounter);
}
if (temprow >= 5)
{
NextSelect.Enabled = true;
}
}
else
{
MessageBox.Show("Form Field :" + fieldLabel + " already selected", "PDF Perform Info");
}
}
dgvSelectedFieldsView.DataSource = TempTable;
dgvSelectedFieldsView.ClearSelection();
applyFormattingSelectedFieldsTable();
}
我究竟做错了什么?