DataGridViewComboBoxColumn设置selectedIndex [英] DataGridViewComboBoxColumn set the selectedindex
问题描述
您好,我运行时绑定数据到datagridview的组合框。但我怎么让它自动显示的第一个项目?我不能够找到DataGridViewComboBoxColumn将selectedIndex
DataGridViewComboBoxColumn cbStudentCourse =(DataGridViewComboBoxColumn)dgStudentCourse.Columns [studentCourseStatus]。
cbStudentCourse.DataSource = Enum.GetValues(typeof运算(CourseStudentStatus));
cbStudentCourse.DisplayIndex = 1;
- 更新---结果
I看见有人在溶液中做这个3 < BR>
链接结果
你确定我需要这么长的代码只是第一个项目选择??????
A DataGridViewComboBoxColumn 没有的SelectedIndex
和的SelectedValue
属性。然而,你可以通过设置在 值
属性。获取的SelectedValue
的相同的行为p>
上。例如第一个索引值的成员具有值2,那么你应该设置 .value的=2
来设置第一个指标选择。
例如
myDataGridViewComboBoxColumn.Value = 20;
在你的情况
myDataGridViewComboBoxColumn.Value = CourseStudentStatus.EnumToBeSelected.ToString();
下面是关于的 DataGridViewComboBoxColumn
hi i runtime bind the data into datagridview combobox. But how do i make it to auto display the first item? i do not able find the selectedindex from DataGridViewComboBoxColumn.
DataGridViewComboBoxColumn cbStudentCourse = (DataGridViewComboBoxColumn)dgStudentCourse.Columns["studentCourseStatus"];
cbStudentCourse.DataSource = Enum.GetValues(typeof(CourseStudentStatus));
cbStudentCourse.DisplayIndex = 1;
-- Update ---
i saw someone doing this in solution 3
LInk
Are you sure i need such a long code to just have the first item selected??????
A DataGridViewComboBoxColumn has no SelectedIndex
, and SelectedValue
properties. However you can get the same behavior of SelectedValue
by setting the Value
property.
For instance on first index the value member has value 2 then you should set .Value = "2"
to set the first index selected.
For example
myDataGridViewComboBoxColumn.Value = "20";
In your case
myDataGridViewComboBoxColumn.Value = CourseStudentStatus.EnumToBeSelected.ToString();
Here is more details about DataGridViewComboBoxColumn
这篇关于DataGridViewComboBoxColumn设置selectedIndex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!