Combo
Hi,
I have a combobox & i want to fill the combox with data from the database when thr form is initialised.Can anyone tell me the code?
Thanks,
Swetha.
OLEDB
I use this combobox for for selecting records to edit or delete
Private Sub Md_FillCombo()
Try
Dim r As DataRow
comboBoxNo.Items.Clear()
For Each r In dSet.Tables(0).Rows
comboBoxNo.Items.Add(r.Item(0))
Next r
btnUpdate.Enabled = False
btnDelete.Enabled = False
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Here's the code for its indexing
Private Sub comboBoxNo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles comboBoxNo.SelectedIndexChanged
Try
dSet.Tables(0).PrimaryKey = New DataColumn() {dSet.Tables(0).Columns("NO_0")}
Dim row As DataRow
row = dSet.Tables(0).Rows.Find(comboBoxNo.Text)
txtBoxNo.Text = row("NO_0")
txtBoxName.Text = row("NAME_0")
txtBoxGender.Text = row("GENDER_0")
txtBoxDepartment.Text = row("DEPARTMENT_0")
txtBoxTotalMark.Text = row("TOTALMARK_0")
btnUpdate.Enabled = True
btnDelete.Enabled = True
txtBoxNo.ReadOnly = True
btnAdd.Enabled = False
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Hope this helps.