在数据网格视图中动态设置组合框的选定索引 [英] Dynamically set the selected index of a combo box in a data grid view

查看:184
本文介绍了在数据网格视图中动态设置组合框的选定索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我正在尝试在数据网格视图中动态设置组合框的选定索引.我尝试使用选定索引,但是似乎在数据网格视图中没有组合框的选定索引属性.
我该如何设置?
然后从db绑定此组合.

我想我以正确的方式解释了一些问题.

请帮助我

谢谢

Hi all

I am trying to dynamically set the selected index of a combo box in data grid view. I tried with selected index, But it seems there is no selected index property of combo box in data grid view.
How can i set that?
And I bind this combo from db.

I think I explained ma ques in a right way.

Please help me

Thanks

推荐答案

如果您要像在comboBox中一样使用selectedIndex
1.您必须将Items添加到comboBox元素

If you want to work with the selectedIndex like in a comboBox
1. You have to add your Items to the comboBox element

DataGridViewComboBoxColumn1.Items.Add("your Text ");
DataGridViewComboBoxColumn1.Items.Add("your Text1 ");
DataGridViewComboBoxColumn1.Items.Add("your Text2 ");



2.如果要设置selectedIndex,则必须这样做



2. if you want to set the selectedIndex you have to do it like this

int selectedIndex = 1
DataGridView1.Rows[yourrowIndex].cells["YourcomboBox column"].Value = DataGridViewComboBoxColumn1.Items[selectedIndex];



3如果要获取selectedIndex,请执行以下操作



3 if you want to get the selectedIndex do it like this

int selectedIndex = DataGridViewComboBoxColumn1.Items.IndexOf
(DataGridView1.Rows[yourrowIndex].cells["YourcomboBox column"].Value);

>

很抱歉造成您的耽搁,但我希望能为您提供帮助.



sorry for the delay and my englisch but i hope it will be helpfull


您好...

我找到了解决方案,我们可以在数据网格视图中将组合框的索引设置为
Hi..

I Found out a solution to this,We can set the index of combo box in a data grid view as
Datagridview1.Rows[yourrowIndex].cells["Your combobox column"].value=//set the value member here



对我来说真的很有效

谢谢



it really works for me

Thanks


这篇关于在数据网格视图中动态设置组合框的选定索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆