listbox datavaluefield and datatextfield

T

tshad

How do I get to the datatextfield of listbox?

I can get the the datavaluefield using the selectedvalue. I want to get the
text portion of the listbox that the user selected.

Thanks,

Tom
 
G

Guest

Hi,

In a list box the user can select single or multiple values. Below is the
code given for reading the multiple text values of the listbox in a string
seperated by commas.

Dim lCtr
Dim strText as String

If listBox.Items.Count > 0 Then
For lCtr = 1 To lstBox.Items.Count
If istBox.Items(lCtr - 1).Selected = True Then
strText = lstBox.Items(lCtr - 1).Value
' Can have some code to append commas.......


End If
Next
End If

strText would be a string consistes od comma. You may also use the String
Builder class, if you want to optimise the string.

Please let me know if this is what you were looking for.....

Thanks and Regards,

Piyush
 
G

Guest

Tom try using :-
" ddlNamesList.SelectedItem.Text"
e.g ddlNamesList being ur listBox
Patrick
 
T

tshad

tshad said:
How do I get to the datatextfield of listbox?

I can get the the datavaluefield using the selectedvalue. I want to get the
text portion of the listbox that the user selected.

Figured it out.

listbox.SelectedItem.text

It is interested that for the value you can use either:

listbox.SelectedValue or listbox.SelectedItem.Value

I'm surprised that there isn't a listbox.SelectedText also (to be
consistant).

Tom
 

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

Members online

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top