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. Image for the cookie policy date

Display Data From Other Tables with GridDataBounGrid

As it is possible to be shown data of other tables in a GridDataBounGrid ?

5 Replies

AD Administrator Syncfusion Team October 15, 2004 08:05 AM UTC

You can handle foreign key tables by using ComboBox celltypes for your key column setting the style.DataSource, style.ValueMember and style.DisplayMember to you foreign key table items. See http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=1514. If you want to add new column (no existing column in the table is a foreign key pair), then currently you have to add an unbound column, and use grid.Model.QueryCellInfo to provide the values for this unbound column. The grid\samples\databound\then GDBGMultiHeader sample shows how to add unbound columns. In this case, you would get the unbound values from your second table.


FE Fernando October 15, 2004 09:42 AM UTC

What I really want is to show a TextBox instead of a ComboBox. Example: Table of the GridDataBoundGrid ==> Products Instead of the CategoryID column of the Products table, I want that it appears the value of the CategoryName field of the Categories table. >You can handle foreign key tables by using ComboBox celltypes for your key column setting the style.DataSource, style.ValueMember and style.DisplayMember to you foreign key table items. See http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=1514. > >If you want to add new column (no existing column in the table is a foreign key pair), then currently you have to add an unbound column, and use grid.Model.QueryCellInfo to provide the values for this unbound column. The grid\samples\databound\then GDBGMultiHeader sample shows how to add unbound columns. In this case, you would get the unbound values from your second table.


AD Administrator Syncfusion Team October 15, 2004 10:31 AM UTC

Using the combobox is the way to do this. The ComboBox will look like a textbox if you hide the button (style.ShowButton = GridShowButton.Hide). This is the simplest way to get this look. If you really don''t want to use the combobox, then using an unbound column is one appraoch to get what you want. Another would be to handle the QueryCellFormattedText/SaveCellFormattedText and swap the values those events. If your cell is readonly (just for display), another option would be to use the DrawCellDisplayText event and swap the text there. But it will be much simpler just to set properties to make the column use the combobox with its foreign support, and hide the button. The Grid\Samples\DataBound\GDBGcombos shows foreign key comboboxes, but it was all done with the designer but you can look at the designer generated code to see how to set such properties from code.


FE Fernando October 19, 2004 04:32 AM UTC

Thank you very much. I have been proving and the only thing that I have arrived to do, is to show the CategoryName field, as I wanted, but now I have another problem, and is that, I want to show another field (for example description) of the Categories table, but I only have the CategoryID to be able to relate it to the table and nonencounter way to do it since since attempt to do gives error me of duplicated MappingName. There is some way to do it? this.gridDataBoundGrid1.DataSource = this.dataSet1; this.gridDataBoundGrid1.DataMember = "Products"; Syncfusion.Windows.Forms.Grid.GridBoundColumn laColumna = new Syncfusion.Windows.Forms.Grid.GridBoundColumn(); laColumna.HeaderText = "Product name"; laColumna.MappingName = "ProductName"; this.gridDataBoundGrid1.GridBoundColumns.Add(laColumna); laColumna = new Syncfusion.Windows.Forms.Grid.GridBoundColumn(); laColumna.HeaderText = "Category"; laColumna.MappingName = "CategoryID"; laColumna.StyleInfo.DataSource = this.dataSet1.CATEGORIES; laColumna.StyleInfo.CellType = "ComboBox"; laColumna.StyleInfo.DisplayMember = "CategoryName"; laColumna.StyleInfo.ValueMember = "CategoryID"; this.gridDataBoundGrid1.GridBoundColumns.Add(laColumna); laColumna.StyleInfo.ShowButtons = Syncfusion.Windows.Forms.Grid.GridShowButtons.Hide; this.gridDataBoundGrid1.Binder.InitializeColumns();


AD Administrator Syncfusion Team October 19, 2004 05:28 AM UTC

If you want to display multiple foreign columns, then it is probably simpler just to use unbound columns to do this. If you want to use ComboBoxes like you are doing now, you would have to add alias columns to your sql query to get duplicate columns (with diffferent column names) in your main DataTable. Here is a sample using unbound columns to display 2 foreign columns based on the same ID field in the main table. It shows the foreign key in the grid as well as the two additional foreign columns. This lets you edit the foreign key which adds some additional code. If you do not need this editing of the foreign key, the cm.ItemChanged event handler can be removed. percent_8844.zip

Loader.
Live Chat Icon For mobile
Up arrow icon