C#中的运行时DatagridView [英] Runtime DatagridView in C#
问题描述
我正在使用datagridview属性..
在datagridview我使用3列,即名称(字符串),类型(组合框),年龄(字符串)..
组合框中的
,项目是男性,女性
默认情况下,我得到
1.Name
Vino
2.Type
3.Age
22
i需要将datagridview组合框的第0个索引值显示为默认值..
必填,
1.名
Vino
2.Type
男
3.Age
22
请在加载时帮我获取datagridviewcolumnindex dyamiclly ....
i am using a datagridview property..
in datagridview i use 3 columns namely name(string), type(combobox), Age(string)..
in combobox , the items are Male, Female
By default,i get
1.Name
Vino
2.Type
3.Age
22
i need to show the datagridview combobox's 0th index value as default ..
Required,
1.Name
Vino
2.Type
Male
3.Age
22
Please help me to get the datagridviewcolumnindex dyamiclly when load....
推荐答案
提供示例代码..
或
尝试在合并框中将Male作为Text / NullText
give your sample code..
or
Try to give Male as your Text/NullText in combobox
在datagrid的RowAdded事件中尝试此代码。
In RowAdded event of datagrid try this code.
DataGridViewComboBoxCell cell = dataGridView1.Rows[e.RowIndex].Cells[1] as DataGridViewComboBoxCell;
if (cell != null)
{
cell.Value = cell.Items[0];
}
希望对您有所帮助。
Hope it help you.
这篇关于C#中的运行时DatagridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!