c# - Problem getting selected row values to combo box from datagridview cell click in c#
问题描述
I have two forms Form1 and Form2. I am facing problem loading Datagridview cell value of Form1 to the combo box of Form2 on cell double click event as show in the screenshot. using below code, text box values getting properly from the row i had selected but combo box shows empty.
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex != -1 && e.ColumnIndex != -1)
{
Form2 fo = new Form2();
DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
fo.textBox1.Text = row.Cells["firstNameGV"].Value.ToString();
fo.textBox2.Text = row.Cells["lastNameGV"].Value.ToString();
fo.comboBox1.Text = row.Cells["deptGV"].Value.ToString();
fo.ShowDialog();
}
}
how do i get the values in combo box. (p.s: combo box on Form2 is filled from database on form_loadevent values can also be seen in the attachment.)
private void Form2_Load(object sender, EventArgs e)
{
loadItems();
comboBox1.SelectedIndex = -1;
}
解决方案
推荐阅读
- java - 如何在同一项目的其他类中使用公共类报告(用于记录目的)和公共静态方法
- c# - 如何在 Unity 中旋转 Vector3
- react-native - 带有 React Native 的 ClojureScript - 文件下载
- r - 使用 layout() 时 ploty r 无法绘图
- xml - 是否可以运行一个 build.xml 文件,该文件又执行另一个 build.xml 文件
- sapui5 - 无法在 sapui5 中使用 splitcontainer 在详细页面中显示数据?
- karabiner - 如何在 Karabiner-Elements 中创建重新映射插入键到 command+option+I
- java - 有效更新 RecyclerView Grid 或以其他方式显示复杂网格
- python - 运行 appium 测试时禁用警告
- php - 从教义2开始创建模式问题