如何在windows窗体的datagridview中获取组合框控件值? [英] How to get the combobox control value in a datagridview in windows form?
问题描述
我正在使用Windows应用程序,并且包含一个包含数据网格视图的表单,该数据网格视图具有绑定和未绑定的控件。我的下拉菜单有2个部分 - 项目和值。 (A =某个值1; B =某个值2,依此类推)。 Item = A; B ... Value = some value1;一些价值2 .....
用户在下拉菜单中看到这个 - 有些值1
进入子表的值是:A = somevalue1
我需要在数据库表中输入项目A,但是很难抓住它。
文本字段加载到数据库正常。如何从datagridview下拉列表中获取正确的值?
我目前有:
I am working with a windows app and have a form that contains a datagridview that has bound and unbound controls. My dropdowns have 2 parts - item and the value. (A = some value1; B = some value2, and so on). Item = A;B... Value = some value1; some value2.....
The user sees this in the dropdown - "some value1"
The value going into the subtable is: "A = somevalue1"
I need to enter Item "A" into the database table, but am having difficulty grabbing it.
The text fields load to the database fine. How do I get the correct value from the datagridview dropdowns?
I currently have:
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
if ((dataGridView1.Rows[i].Cells[j].Value != null) &&
(dataGridView1.Rows[i].Cells[j].Value.ToString().Trim() != ""))
{
myRow[dataGridView1.Columns[j].Name.Trim()] = dataGridView1.Rows[i].Cells[j].Value.ToString().Trim();
l_blnWrite = true;
}
else
{
l_blnWrite = false;
break;
}
}
if (!l_blnSavedRecord)
{
if(l_blnWrite)
ds.Tables[l_strTable].Rows.Add(myRow);
}
}
推荐答案
是的,有一些列的字段类型组合,文本和组合框。
Yes, there are a combination of field types that are columns, Text and combo boxes.
这篇关于如何在windows窗体的datagridview中获取组合框控件值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!