|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
custom field in DataTable for listbox bindingHi:
I have a dialog in WinForm with 2 list box, source and destination, and 4 buttons, add, add all, remove and remove all. So user can add single/all items in source list box to destination one. so as remove and remove all buttons. I binding a DataTable to source and destination list box. Now my problem is, in my DataTable, there are fields ID, FirstName, LastName. I like to show full name in the list box. What should I do? The ListBox control cannot show more than one field at a time, so I suggest
you adding a new calculated field to the datatable witih LastName and FirstName concatenated. Something like this: SourceTable.Columns.Add("FullName", GetType(String), "LastName + ', ' + FirstName") Me.ListBox1.DataSource = SourceTable Me.ListBox1.DisplayMember = "FullName" Me.ListBox1.ValueMember = "ID" Regards from Madrid (Spain) Jesús López VB MVP Show quote "wesbird" <wesb***@discussions.microsoft.com> escribió en el mensaje news:20052910-52D9-42AE-A6C9-1DD6C8A4D3CA@microsoft.com... > Hi: > I have a dialog in WinForm with 2 list box, source and destination, and 4 > buttons, add, add all, remove and remove all. So user can add single/all > items in source list box to destination one. so as remove and remove all > buttons. I binding a DataTable to source and destination list box. Now my > problem is, in my DataTable, there are fields ID, FirstName, LastName. I > like > to show full name in the list box. > What should I do? Write your SELECT to do the concatenation:
SELECT FirstName + " " + LastName AS [Name] FROM ... -- Show quote____________________________________ William (Bill) Vaughn Author, Mentor, Consultant Microsoft MVP INETA Speaker www.betav.com/blog/billva www.betav.com Please reply only to the newsgroup so that others can benefit. This posting is provided "AS IS" with no warranties, and confers no rights. __________________________________ "wesbird" <wesb***@discussions.microsoft.com> wrote in message news:20052910-52D9-42AE-A6C9-1DD6C8A4D3CA@microsoft.com... > Hi: > I have a dialog in WinForm with 2 list box, source and destination, and 4 > buttons, add, add all, remove and remove all. So user can add single/all > items in source list box to destination one. so as remove and remove all > buttons. I binding a DataTable to source and destination list box. Now my > problem is, in my DataTable, there are fields ID, FirstName, LastName. I > like > to show full name in the list box. > What should I do? wesbird,
> Write your SELECT to do the concatenation: Juan and Bill give you the in my opinion two nicest alternatives (it is just > SELECT FirstName + " " + LastName AS [Name] FROM ... > what you prefer). Probably do you need for the combobox value as well the ID, in the select from Bill. Just as very slight addition to Bills string :-) Cor |
|||||||||||||||||||||||