Saturday, March 24, 2012

ListBox

Dear All,
I have a table in the database called languages in which I have different
languages and each language has a unique ID associated with it.I have
attached this language table with a dropdownbox.It displays all the
languages in the drop down. Now what I am trying to do is to add 1 langauge
at a time in the ListBox in the click event of the button.But when I click t
he
button It does not display the Language but displays only that unique number
which is associated with it. For eg. If French has a number 3 in the databas
e
it displays 3 in the listbox instead of text French.which I don't want.Can s
ome
one tell me how to display only the languages and not their unique numbers.
Any help much appreciated.
cheers,
Sunil Sabir
IYou need to set the DataTextField of the ListBox to the name of the column t
hat cotains French, and the DataValueField to the name of the column contain
s 3.

> Dear All,
>
> I have a table in the database called languages in which I have dif
ferent
> languages and each language has a unique ID associated with it.I ha
ve
> attached this language table with a dropdownbox.It displays all the
> languages in the drop down. Now what I am trying to do is to add 1
langauge
> at a time in the ListBox in the click event of the button.But when
I click the
> button It does not display the Language but displays only that uniq
ue number
> which is associated with it. For eg. If French has a number 3 in th
e database
> it displays 3 in the listbox instead of text French.which I don't w
ant.Can some
> one tell me how to display only the languages and not their unique
numbers.
> Any help much appreciated.
> cheers,
> Sunil Sabir
> I
"Sunil Sabir" <SunilSabir@.discussions.microsoft.com> wrote in message
news:6C6B6CE4-5869-418C-85F4-719B60F5A6AE@.microsoft.com...
> Dear All,
>
> I have a table in the database called languages in which I have
different
> languages and each language has a unique ID associated with it.I
have
> attached this language table with a dropdownbox.It displays all the
> languages in the drop down. Now what I am trying to do is to add 1
langauge
> at a time in the ListBox in the click event of the button.But when
I click the
> button It does not display the Language but displays only that
unique number
> which is associated with it. For eg. If French has a number 3 in
the database
> it displays 3 in the listbox instead of text French.which I don't
want.Can some
> one tell me how to display only the languages and not their unique
numbers.
> Any help much appreciated.
> cheers,
> Sunil Sabir
> I
Try putting the key field in the ValueMember property and the description
field in the DisplayMember property.
This works here with fields from a table pulled into a DataSet used as the
DataSource for a ListBox.
Hope this helps.
Peter [MVP Visual Developer]
Jack of all trades, master of none.
"Sunil Sabir" <SunilSabir@.discussions.microsoft.com> wrote in message
news:6C6B6CE4-5869-418C-85F4-719B60F5A6AE@.microsoft.com...
> Dear All,
>
> I have a table in the database called languages in which I have
different
> languages and each language has a unique ID associated with it.I
have
> attached this language table with a dropdownbox.It displays all the
> languages in the drop down. Now what I am trying to do is to add 1
langauge
> at a time in the ListBox in the click event of the button.But when
I click the
> button It does not display the Language but displays only that
unique number
> which is associated with it. For eg. If French has a number 3 in
the database
> it displays 3 in the listbox instead of text French.which I don't
want.Can some
> one tell me how to display only the languages and not their unique
numbers.
> Any help much appreciated.
> cheers,
> Sunil Sabir
> I
My apologies.
I used the WinForm ListBox property names instead of the WebForm ListBox
property names. David used the correct names in his response.
Same principle, though.
Sorry about that!
Peter [MVP Visual Developer]
Jack of all trades, master of none.

0 comments:

Post a Comment