Friday, March 16, 2012

listbox datavaluefield and datatextfield

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,
TomHi,
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
"tshad" wrote:

> How do I get to the datatextfield of listbox?
> I can get the the datavaluefield using the selectedvalue. I want to get t
he
> text portion of the listbox that the user selected.
> Thanks,
> Tom
>
>
Tom try using :-
" ddlNamesList.SelectedItem.Text"
e.g ddlNamesList being ur listBox
Patrick
"tshad" wrote:

> How do I get to the datatextfield of listbox?
> I can get the the datavaluefield using the selectedvalue. I want to get t
he
> text portion of the listbox that the user selected.
> Thanks,
> Tom
>
>
"tshad" <tfs@.dslextreme.com> wrote in message
news:uAoRPYRVFHA.228@.TK2MSFTNGP12.phx.gbl...
> 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
> Thanks,
> Tom
>

0 comments:

Post a Comment