如何设置Default Combobox Selected值 [英] How to set Default Combobox Selected value
本文介绍了如何设置Default Combobox Selected值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮助我
我在组合框中有五个值
例如:
Chennai
班加罗尔
Trivandrum
印度
美元
表格显示时
i想要显示第4个值(印度)默认选择
代码是什么
Please help me
I have five values in combobox
Example:
Chennai
Bangalore
Trivandrum
India
US
when the form is display
i want to display 4th value (India) is selected by default
what is the code
推荐答案
试试这个:
combobx1.Text =印度
但如果您有数据网格视图则不同:
通过代码创建它:
try this :
combobx1.Text = "India"
but if you have a datagridview it's different :
to create it by code :
string[] str = {"Chennai","Bangalore","Trivandrum","India","US"};
DataGridViewComboBoxColumn cmb = new DataGridViewComboBoxColumn();
cmb.HeaderText = "Headertext";
cmb.Name = "name";
cmb.MaxDropDownItems =str.Count() ;
foreach (String o in str)
{
cmb.Items.Add(o);
}
dataGridView.Columns.Add(cmb);
然后更改你应该使用的文字:
then to change the text you should use :
for (int i = 0; i < dataGridView.Rows.Count - 1; i++)
{
dataGridView.Rows[i].Cells[where the combobx located].Value = "India";
}
尝试comboBoxLocation.SelectedIndex = 3
Try comboBoxLocation.SelectedIndex=3
在Form加载事件上写下此代码
Write this code on your Form load event
combobox1.SelectedIndex=combobox1.FindStringExact("India");
谢谢&注意
Sham:)
Thanks & Regard
Sham :)
这篇关于如何设置Default Combobox Selected值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文