【发布时间】:2019-06-30 06:46:27
【问题描述】:
我希望当我单击 datagridview 行时,我的两个文本框和 combobox 填充相应的值,但两个文本框准确填充但类别下拉列表未填充。
我的 C# 代码是
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex != -1 && e.ColumnIndex !=-1)
{
//edit = 1;
DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
proID = Convert.ToInt32(row.Cells["proIDGV"].Value.ToString());
proTxt.Text = row.Cells["nameGV"].Value.ToString();
barcodetxt.Text = row.Cells["barcodeGV"].Value.ToString();
catDD.SelectedValue = row.Cells["catIDGV"].Value.ToString();// not working properly due to which edit button is not working
// catDD.SelectedItem = row.Cells["catGV"].Value.ToString();//Also Write this line of code but not produce the desire result
MainClass.Disabled(leftPanel);
}
}
【问题讨论】:
-
先生,我在 windowForms 工作
-
你需要告诉我们你是如何设置ComboBox的DataSource的。
-
组合框中的项目是否填写正确?您的代码仅显示选择不填充。
-
检查comboBox的值,其值应与datagridview选择的行类别值相匹配
-
如果 combobx.Items 中的值填充了 DGV 列中的可能值,那么
catDD.SelectedItem= row.Cells["catIDGV"].Value.ToString();应该可以工作。如果不是,则值或列名不正确。