Click here to Skip to main content
16,015,393 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello all
i have a field in DB which is used for putting some text.Eg:admin,client,driver,fifi.
and in a form application i have a combobox with same text(with index 0 to 3),so i plan to read from DB and then set the "index of combobox" with that text.for example one record is "FIFI",and related index of combobox in form application is first index(0 index),so when FIFI will read from DB,combobox will set with first value.
how can i do that?
thanks all
Posted
Updated 6-Feb-12 0:37am
v2

 
Share this answer
 
hi select the DropDownList.in DropDownList Tasks select Choose data source.after that make a connection string to ur data base and select the table that u want.
At the end select a Data field to display in the DropDownList, and select the value.
 
Share this answer
 
VB
Public Class cValue 
'I first create a class in my project to handle value from an array
    Private sDisplay As String
    Private sValue As String
    Public Property Display() As String
        Get
            Return Me.sDisplay
        End Get
        Set(ByVal value As String)
            Me.sDisplay = value
        End Set
    End Property
    Public Property Value() As String
        Get
            Return Me.sValue
        End Get
        Set(ByVal value As String)
            Me.sValue = value
        End Set
    End Property

    Public Sub New(ByVal sDisplay As String, ByVal sValue As String)
        Me.Display = sDisplay
        Me.Value = sValue
    End Sub

    Public Overrides Function ToString() As String
        Return Display
    End Function
End Class

VB
Project.Items.Clear() 'My ComboBox
           Dim allProjects As New ArrayList() 'Array with stuff from db
           allProjects.Add(New cValue("", ""))
           For i = 0 To rs.Row.Length - 1 'Loop through the array to add the Values 
               allProjects.Add(New cValue(rs.Row(i).Property(0).Value,     rs.Row(i).Property(1).Value))'Read from recordset to my array
           Next
 Project.DataSource = allProjects
            Project.DataSource = allProjects 'set my array as the source for combo
            Project.DisplayMember = "Display"
            Project.ValueMember = "Value"
Project.SelectedIndex = 0
 
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