DataGridViewComboBoxColumn - Multiple columns as .DisplayMember?
-
Hi All, Easiest to explain if I show an example: I have a DataGridView which has a column that is a combo box. I have a dataset as the source, it has two columns: FirstName and LastName. I want the combo box to display "LastName, FirstName", ie, I want the display member to be a combination of two columns. Is this possible? Or will I have to add a new column to my dataset "FullName" which will be the two added together? Cheers, Brad
-
Hi All, Easiest to explain if I show an example: I have a DataGridView which has a column that is a combo box. I have a dataset as the source, it has two columns: FirstName and LastName. I want the combo box to display "LastName, FirstName", ie, I want the display member to be a combination of two columns. Is this possible? Or will I have to add a new column to my dataset "FullName" which will be the two added together? Cheers, Brad
-
Hi All, Easiest to explain if I show an example: I have a DataGridView which has a column that is a combo box. I have a dataset as the source, it has two columns: FirstName and LastName. I want the combo box to display "LastName, FirstName", ie, I want the display member to be a combination of two columns. Is this possible? Or will I have to add a new column to my dataset "FullName" which will be the two added together? Cheers, Brad
The combobox only handles a single column of displayed data. It has a displaymember and a valuemember property for binding to the datasource. But if you must display multicolumn in a combobox then you can concatenante your column values, like Eddy's shown in SQL. In VB this works like:
Dim FnLn As String
Dim drRow As DataRow
For Each drRow In DataSet.Rows 'or DataSet.Tables("Table1").Rows
FnLn = drRow("Lastname") & " , " & drRow("Firstname")
cb1.Items.Add(FnLn)
Next