المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Problem to display relational data in dataGridView in Entity Framework.



C# Programming
10-14-2009, 10:10 AM
Hi
i have a simple winform app which have a dataGridView to display Orders table from northwind database. i want to display foreign keys in dataGridView with some related column from reference table, for example display CompanyName instead of CustomerID (even display customerID in comboBox). for this, i change my dataGridViewTextBox column type to comboBox, then bind it to customerBindingSource (which fill out from Customers entitySet), then set DisplayMember and ValueMember to customerID, but at runTime it does not display corresponding customerID for that order (display nothing) for loaded order records.
Here my disegner generated code (the CustomerID is my dataGridViewComboBox column):


this.CustomerID.DataSource = this.customerBindingSource;
this.CustomerID.DisplayMember = "CustomerID";
this.CustomerID.HeaderText = "Customers";
this.CustomerID.Name = "CustomerID";
this.CustomerID.Resizable = System.Windows.Forms.DataGridViewTriState.True;
this.CustomerID.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
this.CustomerID.ValueMember = "CustomerID";

how to workaround the problem ?
regards