Link to home
Start Free TrialLog in
Avatar of LeeHopkins
LeeHopkinsFlag for United States of America

asked on

how to insert a value at index 0 of a combobox.

I have a query that I run to fill a combo box. it has a valuemember _recid and displaymember "text"
I want the first value to be valuemember =0 and displaymember to be "Please Select a Title"

How can i insert this new value at cboindex 0
Dim magdt As DataTable = New DataTable
            Dim strQuery As String
            strQuery = "Select A_ID, A_Name from tbl_Art order by 2"
            Dim myadapter As New SqlDataAdapter(strQuery, connstring)
            myadapter.Fill(magdt)
            Me.cboAName.DataSource = magdt
            Me.cboAName.DisplayMember = "A_Name"
            Me.cboAName.ValueMember = "A_ID"

Open in new window

Avatar of Chiliyago
Chiliyago
Flag of United States of America image

You need to use the Items.Insert() method like so:

Me.cboAName.Items.Insert(0, myCombolistItme)

ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of srikanthreddyn143
srikanthreddyn143

Insert into dataset as

ds.Tables(0).Rows.InsertAt(ds.Tables(0).NewRow, 0)
            ds.Tables(0).Rows(0)(DisplayMember) = Display text
            ds.Tables(0).Rows(0)(Value Member) = 0
magdt.Tables(0).Rows.InsertAt(magdt.Tables(0).NewRow, 0)
            magdt.Tables(0).Rows(0)(A_Name) = "Please Select a Title"
            magdt.Tables(0).Rows(0)(A_ID) = 0
Avatar of LeeHopkins

ASKER

i like this method it is very flexable on adding other items