我有一个包含2列的DataGridView(dgvTable)。 第一列包含具有来自数据库的预设数据的组合框。 第二列只是文字。 我试图根据第二列中的信息设置第一列中组合框的选择。
我将我的代码简化为我需要的帮助:
string data = "MATCH THIS VARIABLE"; foreach (DataGridViewRow row in dgvTable.Rows) { if (match.Equals(row.Cells[1].Value.ToString())) //checking to see if the second column value matches data { row.Cells[0].Value = "HELP"; //if the second column value == data then set the combobox selected value to "HELP" } }组合框不显示值
编辑:我开始了一个新项目,并创建了一个datagridview并添加了一个columncombobox。 我确实成功设置了组合框的值。 唯一的区别是我试图在单独的窗口中更改datagridview组合框值。 这会改变什么吗?
I have a DataGridView (dgvTable) with 2 columns. The first column contains combo boxes with preset data from a database. The second column is just text. I am trying to set the selection of the combo boxes in the first column based on the information in the second.
I simplified my code a bit to what I need help with:
string data = "MATCH THIS VARIABLE"; foreach (DataGridViewRow row in dgvTable.Rows) { if (match.Equals(row.Cells[1].Value.ToString())) //checking to see if the second column value matches data { row.Cells[0].Value = "HELP"; //if the second column value == data then set the combobox selected value to "HELP" } }The combo boxes doesn't show the value
EDIT: I started a new project and made a datagridview and added a columncombobox. I did set the value of the combobox successfully. The only difference is I am trying to change the datagridview combobox value in a separate window. Would that change anything?
最满意答案
DropDownList ddl = (DropDownList)e.Row.FindControl("ddlName"); ddl.SelectedValue = "HELP"; DropDownList ddl = (DropDownList)e.Row.FindControl("ddlName"); ddl.SelectedValue = "HELP";更多推荐
发布评论