在Datagridview列中设置组合框(Set Combo Box in Datagridview Column)

编程入门 行业动态 更新时间:2024-10-19 18:18:31
在Datagridview列中设置组合框(Set Combo Box in Datagridview Column)

我有一个包含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";

更多推荐

本文发布于:2023-07-04 17:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1026925.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组合   Set   Datagridview   Column   Box

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!