DataTextField DropDownlist

R

Rafael Metring

How set DAtaTextField and DataValueField in dropdOwnlist

I use this to populate..

Dim sqlConn As SqlCeConnection = Nothing

Dim dr As SqlCeDataReader

Dim da As SqlCeDataAdapter

Dim ds As DataSet = New DataSet

Dim strsql As String

Try

sqlConn = New SqlCeConnection("Data Source =\My Documents\multiseguros.sdf")

Dim insertCommand As SqlCeCommand = sqlConn.CreateCommand()

strsql = "select * from Produto"

sqlConn.Open()

da = New SqlCeDataAdapter(strsql, sqlConn)

da.Fill(ds)

lstProduto.DataSource = ds.Tables(0).DefaultView

lstProduto.Refresh()

Catch err As SqlCeException

MessageBox.Show(err.Message)

Finally

If sqlConn.State = ConnectionState.Open Then

sqlConn.Close()

End If

End Try
 
W

William Ryan eMVP

Rafael:
Rafael Metring said:
How set DAtaTextField and DataValueField in dropdOwnlist

I use this to populate..

Dim sqlConn As SqlCeConnection = Nothing

Dim dr As SqlCeDataReader

Dim da As SqlCeDataAdapter

Dim ds As DataSet = New DataSet

Dim strsql As String

Try

sqlConn = New SqlCeConnection("Data Source =\My Documents\multiseguros.sdf")

Dim insertCommand As SqlCeCommand = sqlConn.CreateCommand()

strsql = "select * from Produto"

sqlConn.Open()

da = New SqlCeDataAdapter(strsql, sqlConn)

da.Fill(ds)

lstProduto.DataSource = ds.Tables(0).DefaultView

lstProduto.Refresh()

Catch err As SqlCeException

MessageBox.Show(err.Message)

Finally

If sqlConn.State = ConnectionState.Open Then

sqlConn.Close()

End If

End Try

The .DisplayMember and .ValueMember fields are probably what you are looking
for
 
P

Peter Foot [MVP]

Use the DisplayMember and ValueMember properties of the ComboBox to define
which fields are to be displayed and used as the value member when
retrieving the user's selection:-
lstProduto.DisplayMember = "DisplayFieldName"
lstProduto.ValueMember = "ValueFieldName"

Where you substitute the fieldnames from your datasource.

Peter
 
R

Rafael Metring

Tanks willian and Petter

Rafael

Peter Foot said:
Use the DisplayMember and ValueMember properties of the ComboBox to define
which fields are to be displayed and used as the value member when
retrieving the user's selection:-
lstProduto.DisplayMember = "DisplayFieldName"
lstProduto.ValueMember = "ValueFieldName"

Where you substitute the fieldnames from your datasource.

Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top