We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Combo Box in Grid (GDBG) using two related tables. Displaymember from T1 but ValueMember from T2

Thread ID:

Created:

Updated:

Platform:

Replies:

14118 May 18,2004 03:19 PM May 19,2004 07:58 AM Windows Forms 6
loading
Tags: GridControl
Harish Batra
Asked On May 18, 2004 03:19 PM

Two tables: Accounts and Companies Accounts (AcctID, AcctNmbr, AcctName, CompID) -- AcctID is PK and CompID is Foreign Key from Companies. Companies (CompID, CompName) -- CompID is PK. Created a DataSet AcctDS with two Data Tables, Acct and Comp Created a grid (GDBG) and I want to show the following in the Grid: AcctNmbr AcctName Company where Company is a ComboBox, whose values will be derived from the Companies table. I only want to show CompName in the combo box. DisplayMember is CompName from Comp Data Table and ValueMember is CompID from Acct Data Table. So, a user can pick CompName from the drop down combo box, but the actual value will be stored as CompID in the Accounts table. Can I just have a visual view of what I want to show (drag and drop items from the view) and then specify the column style (whether it is a combo box, text box etc.)? How do I drag and drop items on to the grid from the view? Please reply Thanks

Administrator [Syncfusion]
Replied On May 18, 2004 05:32 PM

You can do all this from the designer. 1) Create a Dataset with your two tables, Acct and Comp. 2) Drop a GridDataBoundGrid on your form, and set its DataSource to the Acct table. 3) In the GridBoundColumns collection of the grid, add AcctNmbr, AcctName, Company GridBoundColumns bound to the AcctNmbr, AcctName, CompID columns in the Acct table. 4) In the CompID GridBoundColumn, set the styleinfo.CellType to ComboBox, set the styleinfo.DataSource to the Comp table, set the styleinfo.DisplayMember to CompName, and the styleinfo.ValueMember to CompID. You do not drag and drop in steps, but do choose everything from dropdowns in the property grid for the GridDataBoundGrid.

Harish Batra
Replied On May 19, 2004 06:20 AM

Clay: How do I perform step 3 and 4 from the designer (Vis Studio IDE)?

Administrator [Syncfusion]
Replied On May 19, 2004 06:33 AM

After setting the DataSource property for the grid, find the GridBoundColumns property in the gridDataBoundGrid''s property window. Then open up the collection editor, adding the columns you want. Make sure you set the MappingName property for each of the added columns as this is what tells the grid what columns are being used in this GridBoundColumn object. In the collection editor showing each of the GridBoundColumns, there is a StyleInfo property where you set the CellType, DataSource, DisplayMember and ValueMember for your special column.

Harish Batra
Replied On May 19, 2004 06:51 AM

I did that, however, no data is display when I run the application.

Harish Batra
Replied On May 19, 2004 06:58 AM

Clay: Just so you know, when I go to the Acct and Comp sqlAdapters respectively I can preview the data by righ clicking and doing "Preview Data". So I do get the data from the respective adapters. Since, I am doing every thing through the designer, do you think I might be doing something wrong? Actually, in writing C# code for apps, when I write the code myself, I use the "fill" command to fill the dataset. But if I search for the word fill in code generated by the designer in this scenario, it doesn''t find the word fill. This is just a quick pointer. Please advise. Thanks

Administrator [Syncfusion]
Replied On May 19, 2004 07:58 AM

You will not see the actual data at design time. You should be able to see the columns and headertext that you have set. (You see the same behavior with a Windows Forms DataGrid). At runtime, you still have to call DataAdapter.Fill to get the data loaded (using the settings that you provided at design time). Our GridGroupingControl actually does have a Preview verb that you can use at design time to load the data at design time, but you still have to use DataAdapter.Fill to load it at runtime.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;