setting selected item of combobox

ninjaimp

Well-known member
Joined
Jun 13, 2007
Messages
80
Programming Experience
1-3
HI

I have a combobox which is populated from a datatable.

I hae a list of values also and when one is selected i would like it to highlight the correct value in the combo box and have been trying to no avail.

my code is

VB.NET:
Dim searchrow() As DataRow
        Dim searchrow2() As DataRow
        Dim cellvalue As String = dgvStockComps.Rows(e.RowIndex).Cells(1).Value
        'find component
        searchrow = dtSysComps.Select("[component] = '" & dgvStockComps.Rows(e.RowIndex).Cells(1).Value & "'")
        searchrow2 = dtSysCompsParams.Select("[comp-type] = '" & searchrow(0)(14) & "'")
        Me.drpCompType.SelectedItem = Me.drpCompType.Items.IndexOf(searchrow2(0)(2).ToString)
       
        Me.drpCompType.Update()


eveytime i sellect a value in my list nothing happejns to my combo box (i.e. it goes blank and it doesnt show the sleected item like i would like!:ambivalence:)
 
'This code should give you the general idea of what you can do.
'Get the value from the datatable column and use that as a search criteria returning the combobox index upon success.
'use the index to set the combobox selectedindex property.

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With ListBox1.Items
.Add("One")
.Add("Two")
.Add("Three")
.Add("Four")
End With

With ComboBox1.Items
.Add("One")
.Add("Two")
.Add("Three")
.Add("Four")
End With
End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
ComboBox1.SelectedIndex = ComboBox1.FindString(ListBox1.SelectedItem)
End Sub
End Class
 
Back
Top