Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm using the following code to load a combobox:

C#
string sql = @"SELECT FilmID, Vendor.VendorName || ' ' || Film.Model, Film.Active ";
           sql = sql + @"FROM Film JOIN Vendor ";
           sql = sql + @"USING (VendorID) ";
           sql = sql + @"WHERE Film.Active = 1 OR Film.Active = 'True' ";
           sql = sql + @"ORDER BY Vendor.VendorName, Film.Model";

           SQLiteCommand com = new SQLiteCommand(sql, conn);
           dataTable = new DataTable("Film");
           SQLiteDataAdapter ad = new SQLiteDataAdapter(sql, conn);
           ad.Fill(dataTable);
           dataTable.Rows.Add(99999, eesConstants.EESADDEDIT);
           this._dataSet.Tables.Add(dataTable);
           this.comboboxSessionAnalogFilm.ItemsSource = this._dataSet.Tables["Film"].DefaultView;
           this.comboboxSessionAnalogFilm.DisplayMemberPath = this._dataSet.Tables["Film"].Columns[1].ToString();

I have verified that Column[1] is Vendor.VendorName || ' ' || Film.Model

If I change the DisplayMemberPath to Column[0] (FilmID), or Column[2] (Active) the combobox is updated with that data.

I'm not having any problem with tables that don't have concatenated columns.

Is there a way around this?

Thank you.
Posted

1 solution

You didn't post the XAML but based on the query I'd say the problem is that you don't define an alias for the concatenated column. Because of this it will have some default name.

Try the following query
C#
string sql = @"
SELECT FilmID, 
       Vendor.VendorName || ' ' || Film.Model AS CompleteName, 
       Film.Active 
FROM Film JOIN Vendor 
USING (VendorID) 
WHERE Film.Active = 1 
OR    Film.Active = 'True' 
ORDER BY Vendor.VendorName, Film.Model";

and in XAML define the DisplayMemberPath to "CompleteName"
 
Share this answer
 
Comments
Robert Kamarowski 30-Sep-15 16:33pm    
That worked. Thank you!
Wendelius 1-Oct-15 0:00am    
You're welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900