Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi my name is vishal.
I was wondering what is equivalent of combobox properties of ItemData and List of vb6 in c# windows forms with sql server2008?
I know this is naive question but with this answer i can solve my other problems with combobox in c# windows forms.
Given below is code in vb6 of using ItemData property and List property of combobox into table named:dialyser in Ms access.
VB
Private Sub loadPatientID()
    On Error GoTo errh
    Dim vSQLStr As String
    Dim LPatientID As String
    vSQLStr = "select p.patient_id as patient_id,n.patient_first_name as patient_fname, n.patient_last_name as patient_lname from patient_name n,patient_id p where n.patient_id=p.patient_id and n.status = true and p.patient_id not in (select patient_id from dialyser where deleted_status=false);"
    Dim oRS As New ADODB.Recordset
    If (adoDatabase.State = 0) Then
        adoDatabase.Open
    End If
    oRS.Open vSQLStr, adoDatabase, adOpenForwardOnly, adLockReadOnly
    
    cboPatientID.Clear
    Do While Not oRS.EOF
         '// Do something with the data'
         LPatientID = oRS.Fields("patient_id").Value
         LPatientID = Replace(Space(6 - Len(LPatientID)) & LPatientID, " ", "0")
         cboPatientID.AddItem oRS.Fields("patient_fname").Value & " " & oRS.Fields("patient_lname").Value & "|" & LPatientID
         cboPatientID.ItemData(cboPatientID.NewIndex) = oRS.Fields("patient_id").Value
         oRS.MoveNext
    Loop
    oRS.Close
    Exit Sub
errh:
    MsgBox Err.Description, vbCritical
End Sub
Private Sub Command5_Click()
On Error GoTo errh
Public adoDatabase As New ADODB.Connection
Dim rs As ADODB.Recordset
If (adoDatabase.State = 0) Then
        adoDatabase.Open
rs.Open "dialyser", adoDatabase, adOpenKeyset, adLockOptimistic, adCmdTable
rs.AddNew
    rs("dialyserID").Value = txtDID.Text
    rs("manufacturer").Value = cboManufacturer.Text
    rs("mfr_ref_number").Value = TxtMFRRefNo.Text
    rs("mfr_lot_number").Value = TxtMFRLotNo
    rs("mfr_date").Value = CDate(dtMFRDate.Value)
    rs("exp_date").Value = CDate(dtMFRExpDate.Value)
    rs("start_date").Value = CDate(dtMFRStartDate.Value)
    rs("packed_volume").Value = TxtPVol.Text
    rs("dialyzer_size").Value = cboequipmentType.Text
    rs("patient_id").Value = cboPatientID.ItemData(cboPatientID.ListIndex)
    rs("row_upd_date").Value = CDate(Now)
    rs("user_id").Value = pUserID
    rs.Update
MDIForm1.updateUserActivities rs("agn").Value, 4, txtDID.Text & " - Dialyzer detail was successfully assigned to the patient - (" & cboPatientID.List(cboPatientID.ListIndex) & ")"
    MsgBox "Dialyzer detail was added successfully", vbInformation
    Unload Me
    Exit Sub
errh:
    MsgBox Err.Description, vbCritical
End Sub

where cboPatientID is name of my combobox in vb6 adodb with Ms access.
I just want to know what is equivalent of combobox(cboPatientID) properties ItemData and List of vb6 in c# windows forms.Can anyone help me please?Any help or guidance in solving of this problem would be greatly appreciated.
Posted

1 solution

use displaymember and valuemember

The example provided there in the link is listbox you can use the same code in combobox also
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900