combo in datagridview
-
if u r asking for binding the combo box then here's the code dim con as new oledbconnection("connsctionsting") con.open dim ds as new dataset dim ad as new oledbdataadapter("query",con) ad.fill(ds) combobox1.displaymember="fieldname" combobox1.valuemember="fieldname" combobox1.datasource=ds.tables(0)
-
Select Datagridview. Now Click on smart tag which is on top Right corner then select Option "Edit Column".Now select the column from selected column list which is of combo box type. Now Select Property Items(collection Type) and Press the associated button button.
Rupesh Kumar Swami Software Engineer, Integrated Solution, Bikaner (India)
-
I'm not sure if this will answer your question, but the following code segment first creates a DataTable containing values for my combo box, then creates a column that is inserted into a datagrid. Dim typeDesc As New DataTable Dim dr As DataRow typeDesc.Columns.Add("Indx", Type.GetType("System.Int32")) '0 typeDesc.Columns.Add("Desc", Type.GetType("System.String")) '1 dr = typeDesc.NewRow() dr(0) = 0 : dr(1) = "Rural" typeDesc.Rows.Add(dr) dr = typeDesc.NewRow() dr(0) = 1 : dr(1) = "Suburban" typeDesc.Rows.Add(dr) dr = typeDesc.NewRow() dr(0) = 2 : dr(1) = "Urban" typeDesc.Rows.Add(dr) ' datatable giving values type newCol = New DataGridViewComboBoxColumn newCol.Width = 90 newCol.HeaderText = "Parcel Type" newCol.DataSource = typeDesc newCol.ValueMember = "Indx" newCol.DisplayMember = "Desc" dgvTasks.Columns.Insert(2, newCol) The dgvTasks is the name of the datagrid in which the combo will appear.
Rich Feldman
-
I'm not sure if this will answer your question, but the following code segment first creates a DataTable containing values for my combo box, then creates a column that is inserted into a datagrid. Dim typeDesc As New DataTable Dim dr As DataRow typeDesc.Columns.Add("Indx", Type.GetType("System.Int32")) '0 typeDesc.Columns.Add("Desc", Type.GetType("System.String")) '1 dr = typeDesc.NewRow() dr(0) = 0 : dr(1) = "Rural" typeDesc.Rows.Add(dr) dr = typeDesc.NewRow() dr(0) = 1 : dr(1) = "Suburban" typeDesc.Rows.Add(dr) dr = typeDesc.NewRow() dr(0) = 2 : dr(1) = "Urban" typeDesc.Rows.Add(dr) ' datatable giving values type newCol = New DataGridViewComboBoxColumn newCol.Width = 90 newCol.HeaderText = "Parcel Type" newCol.DataSource = typeDesc newCol.ValueMember = "Indx" newCol.DisplayMember = "Desc" dgvTasks.Columns.Insert(2, newCol) The dgvTasks is the name of the datagrid in which the combo will appear.
Rich Feldman