Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid, ComboBox and Default Values

Status
Not open for further replies.

tc3596

Technical User
Mar 16, 2001
283
0
0
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?

 
Did you try:

Code:
With cmb
  .DataSource = RetrieveOperators() 
  .ValueMember = "OperatorId"
  .DisplayMember = "OperatorName"
  .Width = 150[blue]
  .Text = "123"[/blue]
End With

Just replace 123 with the data from your table

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top