组合框中的selectedIndex [英] selectedindex in combobox
本文介绍了组合框中的selectedIndex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
组合框已填充,但所选索引似乎不起作用,
因为组合框不会显示<-选择状态->"正在显示.
你知道为什么吗?
谢谢
Hi,
The combo box is populated but it seems that the selected index does not work,
because the combo box does not show "<-- Select a Status -->" in display.
Do you know why please?
Thanks
private void PopulateTaskStatus()
{
DataTable dtTaskStatus = TaskStatusGet();
DataRow newRow = dtTaskStatus.NewRow();
dtTaskStatus.Columns["Status"].MaxLength = 50;
newRow["Status"] = "<-- Select a Status -->";
dtTaskStatus.Rows.InsertAt(newRow, 0);
cboStatus.DataSource = null;
cboStatus.Items.Clear();
cboStatus.DisplayMember = "Status";
cboStatus.DataSource = dtTaskStatus;
cboStatus.SelectedIndex = 0;
}
推荐答案
你好,
您可以尝试按文本查找并按值查找
cboStatus.Items.FindByText("Status").Selected = true;或
cboStatus.Items.FindByValue("Status").Selected = true;
Hello,
you can try this find by text and find by value
cboStatus.Items.FindByText("Status").Selected = true; OR
cboStatus.Items.FindByValue("Status").Selected = true;
可以在示例代码中看到我做错了什么吗?
这对于我用过的其他形式也很好用.
谢谢
Can you see what I am doing wrong in my sample code?
This works fine for other forms I use it in.
Thanks
是的,我可以在组合框中看到所有项目.
第一项是<-选择一个项目->
如您在我之前发送的代码中所见,我看不到为什么cboStatus.SelectedIndex = 0;不会在组合框中将该项目显示为选定的项目.
你知道为什么吗?
此方法以其他形式与其他表数据一起使用.
谢谢
yes, I can see all items in the combo box.
The first item is <-- select an item -->
As you can see in th ecode I sent earlier, I do not see why cboStatus.SelectedIndex = 0; does not show this item as the selected item in combobox.
Do you see why?
This method works in other forms with other table data.
Thanks
这篇关于组合框中的selectedIndex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文