Hi ,
I am trying to so something really simple but cant seem to get it right. Below is what i am trying to acheive
1) Loop through an object (not a datatable) and add items to a combobox.
Do While Not pRow Is Nothing
cmbbox.Items.Add(pRow.Value(pRow.Fields.FindField(strfieldname)))
pRow = pFCur.NextRow
Loop
The above works fine but the issues arises when i want to add value and text to combobox, and then have one value as a selected value.
Private Sub loadcombobox(ByVal strtablename As String, ByRef cmbbox As System.Windows.Forms.ComboBox, ByVal strfieldname As String, ByVal strvalue As String, ByVal selectedvalue As String)
'
'
'
'
Dim tempcombo as New ComboBox
Do While Not pRow Is Nothing
tempcombo.ValueMember = (pRow.Value(pRow.Fields.FindField(strvalue))).ToString()
tempcombo.DisplayMember = (pRow.Value(pRow.Fields.FindField(strfieldname))).ToString()
cmbbox.Items.Add(tempcombo)
pRow = pFCur.NextRow
Loop
'
'
'
If Not selectedtext Is String.Empty Then
For i = 0 To cmbbox.Items.Count - 1
If cmbbox.Items(i).ValueMember = selectedvalue Then
cmbbox.SelectedIndex = i
Exit For
End If
Next
'
'
'
'
'
End Sub
I have pasted the code that is causing trouble. can someone please help.
All i am trying to do is populate combobox with multiple items having both valuemember and displaymember and then have one of those selected. Any help is appreciated.
Thanks.
I am trying to so something really simple but cant seem to get it right. Below is what i am trying to acheive
1) Loop through an object (not a datatable) and add items to a combobox.
Do While Not pRow Is Nothing
cmbbox.Items.Add(pRow.Value(pRow.Fields.FindField(strfieldname)))
pRow = pFCur.NextRow
Loop
The above works fine but the issues arises when i want to add value and text to combobox, and then have one value as a selected value.
Private Sub loadcombobox(ByVal strtablename As String, ByRef cmbbox As System.Windows.Forms.ComboBox, ByVal strfieldname As String, ByVal strvalue As String, ByVal selectedvalue As String)
'
'
'
'
Dim tempcombo as New ComboBox
Do While Not pRow Is Nothing
tempcombo.ValueMember = (pRow.Value(pRow.Fields.FindField(strvalue))).ToString()
tempcombo.DisplayMember = (pRow.Value(pRow.Fields.FindField(strfieldname))).ToString()
cmbbox.Items.Add(tempcombo)
pRow = pFCur.NextRow
Loop
'
'
'
If Not selectedtext Is String.Empty Then
For i = 0 To cmbbox.Items.Count - 1
If cmbbox.Items(i).ValueMember = selectedvalue Then
cmbbox.SelectedIndex = i
Exit For
End If
Next
'
'
'
'
'
End Sub
I have pasted the code that is causing trouble. can someone please help.
All i am trying to do is populate combobox with multiple items having both valuemember and displaymember and then have one of those selected. Any help is appreciated.
Thanks.