Hi all i have a combobox which is nicely populated from a binding source. So the problem is the column of the datagrid "Name" is only showing values which comes from the populated drop down list. Those values that is not the same as the droplist is shown empty. can someone tell me why? below is they code for the combobox. I cant printscreen but the describtion is like this. The LIst has 3 names : John , Jake, Jay but the colum has over 10 name , each in its respective cell. The problem when onload it is not showing the other names.
Dim c4 As New DataGridViewComboBoxColumn()
c4.HeaderText = "Name"
c4.Name = "Name"
c4.DataPropertyName = "Name"
c4.DisplayMember = "NamesWithJ"
c4.ValueMember = "NamesWithJ"
c4.DisplayStyleForCurrentCellOnly = False
c4.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
c4.FlatStyle = FlatStyle.Standard
c4.SortMode = DataGridViewColumnSortMode.Automatic
c4.DataSource = AddtBndSrc
c4.Width = 100
Me.DataGrid.Columns.Add(c4)
And here is the code where i create the bindingsource and fill it with value. There is no error with the connection its showing perfectly. It just that the comboboxcolumn is showing null in some of the rows
Try
con = New SqlConnection(strConnection)
cib.Open()
adoAAda = New SqlDataAdapter(StrAddNameQuery, con)
adoAddtRs = New DataSet
adoAAda.Fill(adoAddtRs)
Dim tableAddt As DataTable = adoAddtRs.Tables(0)
Dim colum As DataColumn = tableAddt.Columns(0)
tableAddt.PrimaryKey = New DataColumn() {tableAddt.Columns(0)}
AddtBndSrc.DataSource = adoAddtRs.Tables(0)
con.close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Try
' connection procedure
con = New SqlConnection(strConnection)
con.Open()
adoPAda = New SqlDataAdapter(StrProductQuery, con)
adoProductsRS = New DataSet
adoPAda.Fill(adoProductsRS)
Dim tableProduct As DataTable = adoProductsRS.Tables(0)
Dim colum As DataColumn = tableProduct.Columns(0)
tableProduct.PrimaryKey = New DataColumn() {tableProduct.Columns(0)}
productBndSrc.DataSource = adoProductsRS.Tables(0)
MsgBox(tableProduct.Columns(0).ColumnName.ToString)
con.close
datagridview.Datasource = productBndSrc
Catch ex As Exception
MsgBox(ex.Message)
End Try
You want to merge values for combobox. Some are hardcoded into combo but are pulled from database. If so, you need to added the hardcoded values into datasource before binding to combo.
after following lines ADD THE CODE GIVEN BELOW.
adoAAda.Fill(adoAddtRs)
Dim tableAddt As DataTable = adoAddtRs.Tables(0)
'ADD YOUR HARD CODED NAMES TO DATASOURCE BEFORE BINDING
Dim tableAddt As DataTable = adoAddtRs.Tables(0)
Dim dr As DataRow = tableAddt.NewRow
dr("NamesWithJ") = "My test 1"
tableAddt.Rows.Add(dr)
Dim dr1 As DataRow = tableAddt.NewRow
dr("NamesWithJ") = "My test 2"
tableAddt.Rows.Add(dr1)