G
Guest
I filling a combo box with all 50 states and when I select a customer from a
list box I want to find the identity(listindex) in the combo box which is the
identity stored in the customer record. If I do not sort the states combo box
I'm able to find the correct state(listindex) everytime but if I sort the
combo box in ascending order it is not finding the correct state(index). I
used to do this all the time in VB6 and I'm not sure if it is possible in
VB.NET. Sample code below
Sub FillStateDropDown()
Dim i As Integer
Dim strName As String
Dim Iindex As Integer
objStateDA.FillSchema(objDataSet, SchemaType.Source, "States")
objStateDA.Fill(objDataSet, "States")
For i = 1 To objDataSet.Tables("States").Rows.Count
strName = objDataSet.Tables("States").Rows(i -
1).Item("StateAbrev")
Iindex = objDataSet.Tables("States").Rows(i - 1).Item("StateId")
cboState.DisplayMember = strName
cboState.ValueMember = Iindex
cboState.Items.Add(strName)
'cboState.Items.Insert(Iindex - 1, strName)
Next
End Sub
Private Sub lstNames_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles lstNames.Click
Dim objRow As DataRow
objRow =
objDataSet.Tables("FamilyMembers").Rows.Find(lstNames.SelectedIndex + 1)
txtFirstNm.Text = objRow.Item("FirstNm")
txtMiddleNm.Text = objRow.Item("MiddleNm")
txtLastNm.Text = objRow.Item("LastNm")
txtSSN.Text = objRow.Item("ssn")
txtDOB.Text = objRow.Item("dob")
txtHomePhone.Text = objRow.Item("HomePhone")
txtWorkPhone.Text = objRow.Item("WorkPhone")
cboSex.SelectedItem = objRow.Item("sex")
txtStreet.Text = objRow.Item("street")
txtCity.Text = objRow.Item("city")
cboState.SelectedIndex = objRow.Item("StateId")
cboState.SelectedIndex = cboState.SelectedIndex - 1
txtNotes.Text = "" & objRow.Item("Notes")
End Sub
list box I want to find the identity(listindex) in the combo box which is the
identity stored in the customer record. If I do not sort the states combo box
I'm able to find the correct state(listindex) everytime but if I sort the
combo box in ascending order it is not finding the correct state(index). I
used to do this all the time in VB6 and I'm not sure if it is possible in
VB.NET. Sample code below
Sub FillStateDropDown()
Dim i As Integer
Dim strName As String
Dim Iindex As Integer
objStateDA.FillSchema(objDataSet, SchemaType.Source, "States")
objStateDA.Fill(objDataSet, "States")
For i = 1 To objDataSet.Tables("States").Rows.Count
strName = objDataSet.Tables("States").Rows(i -
1).Item("StateAbrev")
Iindex = objDataSet.Tables("States").Rows(i - 1).Item("StateId")
cboState.DisplayMember = strName
cboState.ValueMember = Iindex
cboState.Items.Add(strName)
'cboState.Items.Insert(Iindex - 1, strName)
Next
End Sub
Private Sub lstNames_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles lstNames.Click
Dim objRow As DataRow
objRow =
objDataSet.Tables("FamilyMembers").Rows.Find(lstNames.SelectedIndex + 1)
txtFirstNm.Text = objRow.Item("FirstNm")
txtMiddleNm.Text = objRow.Item("MiddleNm")
txtLastNm.Text = objRow.Item("LastNm")
txtSSN.Text = objRow.Item("ssn")
txtDOB.Text = objRow.Item("dob")
txtHomePhone.Text = objRow.Item("HomePhone")
txtWorkPhone.Text = objRow.Item("WorkPhone")
cboSex.SelectedItem = objRow.Item("sex")
txtStreet.Text = objRow.Item("street")
txtCity.Text = objRow.Item("city")
cboState.SelectedIndex = objRow.Item("StateId")
cboState.SelectedIndex = cboState.SelectedIndex - 1
txtNotes.Text = "" & objRow.Item("Notes")
End Sub