Hi guys how do you produce a gridview where first row contains text and second row contains a combobox?
i tried the code below but it renders the combobox control into a simple text saying the total item of the combobox.
// create columns
DataColumn column1 = new DataColumn();
column1.Caption = "Attribute";
column1.ColumnName = "Attribute";
column1.DataType = typeof(string);
DataColumn column2 = new DataColumn();
column2.Caption = "Value";
column2.ColumnName = "Value";
column2.DataType = typeof(object);
DataTable dt = new DataTable();
dt.Columns.Add(column1);
dt.Columns.Add(column2);
// populate field
DataRow row1 = dt.NewRow();
row1.ItemArray = new object[] { "Id", "1" };
DataRow row2 = dt.NewRow();
row2.ItemArray = new object[] { "Name", "Vincent" };
ComboBox cbox = new ComboBox();
cbox.DropDownStyle = ComboBoxStyle.DropDownList;
cbox.Items.AddRange(new object[]{1,2,3,4,5});
DataRow row3 = dt.NewRow();
row3.ItemArray = new object[] { "Num of Siblings", cbox};
DataRow row4 =dt.NewRow();
row4.ItemArray = new object[] { "Age", "21" };
dt.Rows.Add(row1);
dt.Rows.Add(row2);
dt.Rows.Add(row3);
dt.Rows.Add(row4);
// populate to datagridview
dataGridView1.DataSource = dt;
dataGridView1.Refresh();
are there any other way? i can also separate the combobox from the datagridview control like when the cell (supposed to be the combobox) is clicked, it will popup a dialogbox with combobox in it (2nd form) but this will make the user fill uncombfortable.
the user require me to have this kind of functionality and it should be in datagridview (fields got it from xml (dynamic fields)). the content of dropdown is just a sample, it will be given different values like when entering gender it will have male and female items instead.
Thanks in advance.