在DataGridViewComboboxColumn上设置所选项目 [英] Set selected item on a DataGridViewComboboxColumn

查看:67
本文介绍了在DataGridViewComboboxColumn上设置所选项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有3个值的DataGridViewComboboxColumn列的datagridview:

I have a datagridview with a DataGridViewComboboxColumn column with 3 values:

小,中,大

我找回用户默认值,在这种情况下为中

I get back the users default which in this case is "Medium"

我想在datagridview中显示一个下拉单元格,但默认值为中。我会在常规组合框中通过执行选定的索引或仅将组合框的Text属性设置为这样做。

I want to show a dropdown cell in the datagridview but default the value to "Medium". i would do this in a regular combobox by doing selected index or just stting the Text property of a combo box.

推荐答案

进入datagridview,最好是进入数据绑定。

When you get into the datagridview it is probably best to get into databinding. This will take care of all of the selected index stuff you are talking about.

但是,如果您想自己进入那里,

However, if you want to get in there by yourself,

DataGridView.Rows[rowindex].Cells[columnindex].Value 

将使您获得并设置与DataGridViewComboBoxColumn关联的值。只需确保提供正确的rowindex和columnindex并将值设置为正确的类型(与DataGridViewComboBoxColumn的ValueMember属性相同的类型)即可。

will let you get and set the value associated to the DataGridViewComboBoxColumn. Just make sure you supply the correct rowindex and columnindex along with setting the value to the correct type (the same type as the ValueMember property of the DataGridViewComboBoxColumn).

这篇关于在DataGridViewComboboxColumn上设置所选项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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