tc3596
Technical User
- Mar 16, 2001
- 283
I have a datagrid on my windows form with a combo box, which I dynamically create at runtime. Everything works great. I choose a value, I save it, it saves correctly. FYI, the datagrid is unbound. However, I can't seem to find a way to populate the combo box with the value from the saved record.
Example: Table1 has field1 = '123'
Combo Box is populated with values (123, 124, 125). User chooses 123, and data is stored as 123 in Table1.
On retreive of this information, I repopulate the combobox with it's list of values, but can't seem to find a way to get a value to display. I'm sure this is simple.
Here is my code.
str = "select Name from att_CrewMembers as CRW "
str = str & "Where MainId = " & gMainId & ""
CrewDataAdapter = New SqlDataAdapter(str, myConnection)
commandBuilder = New SqlCommandBuilder(CrewDataAdapter)
Dim table As New DataTable()
table.Locale = System.Globalization.CultureInfo.InvariantCulture
CrewDataAdapter.Fill(table)
CrewBindingSource.DataSource = table
dgCrew.DataSource = CrewBindingSource
dgCrew.Columns(0).Visible = True
dgCrew.Columns(0).Width = 150
''so far, the datagrid has one column. This adds a second column as a combobox, the default value in system for this field is 123, but i can;t get it to display in datagrid whejn '''editing the data
Dim cmb As New DataGridViewComboBoxColumn
With cmb
.DataSource = RetrieveOperators() 'this is a table of operators for the column
.ValueMember = "OperatorId"
.DisplayMember = "OperatorName"
.Width = 150
End With
dgCrew.Columns.Add(cmb)
'''I do capture the actual value via another query in variable gDefaultOperator
''how do i set the value of combo box in datagrid to = gDefaultOperator (there isn't a selectedvalue property)???
Any help is appreciated here?
Example: Table1 has field1 = '123'
Combo Box is populated with values (123, 124, 125). User chooses 123, and data is stored as 123 in Table1.
On retreive of this information, I repopulate the combobox with it's list of values, but can't seem to find a way to get a value to display. I'm sure this is simple.
Here is my code.
str = "select Name from att_CrewMembers as CRW "
str = str & "Where MainId = " & gMainId & ""
CrewDataAdapter = New SqlDataAdapter(str, myConnection)
commandBuilder = New SqlCommandBuilder(CrewDataAdapter)
Dim table As New DataTable()
table.Locale = System.Globalization.CultureInfo.InvariantCulture
CrewDataAdapter.Fill(table)
CrewBindingSource.DataSource = table
dgCrew.DataSource = CrewBindingSource
dgCrew.Columns(0).Visible = True
dgCrew.Columns(0).Width = 150
''so far, the datagrid has one column. This adds a second column as a combobox, the default value in system for this field is 123, but i can;t get it to display in datagrid whejn '''editing the data
Dim cmb As New DataGridViewComboBoxColumn
With cmb
.DataSource = RetrieveOperators() 'this is a table of operators for the column
.ValueMember = "OperatorId"
.DisplayMember = "OperatorName"
.Width = 150
End With
dgCrew.Columns.Add(cmb)
'''I do capture the actual value via another query in variable gDefaultOperator
''how do i set the value of combo box in datagrid to = gDefaultOperator (there isn't a selectedvalue property)???
Any help is appreciated here?