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.
Syncfusion Feedback

Bound and Unbound columns in GDBG

Thread ID:





27282 Apr 8,2005 03:38 PM UTC Apr 8,2005 10:32 PM UTC WinForms 3
Tags: GridControl
Brandon Richter
Asked On April 8, 2005 03:38 PM UTC

Hi, Is there a sample I can look at that shows how to manage a GDBG with both bound and unbound columns? I''m looking for a way to add a few status columns and other calculated columns to the grid in addition to the columns from the datatable. The catch is that I still want to be able to sort and reorder columns in the grid. I handle sorting and filtering via the DefaultView on the datatable by trapping click events on column headers. I let the grid manage the drag-reordering of columns. I also don''t want to have to define types and formats of the bound columns since I''m creating a class that will be used with many tables and thousands of different columns -- I don''t want to set up a style for each one. Is there a sample showing how this can be done?

Administrator [Syncfusion]
Replied On April 8, 2005 04:50 PM UTC

The \Essential Suite\\Windows\Grid.Windows\Samples\DataBound\GDBGMultiHeader has an unbound column in it. But it does not move the unbound values as the columns are sorted. Here is what I think is the simplest way to do this, and it assumes your datatable datasource has a primary key value that can be used to uniquely identify records. Create a hashtable using the primary key value for the record as the key value in the hashtable. As the Value in the hashtable, use an object that holds all your unbound values for that record. The handle the grid.Model.QueryCellInfo (as in the above referenced samle), but instead fo getting the values based on e.RowIndex directly, use code like this to retrieve the primary key value, an dthen use this key in the hashtabke to retrieve the proper unbound object for the requested row. if(e.ColIndex == grid.Binder.NameToColIndex("UnBoundCol")) { int pos = this.grid.Binder.RowIndexToPosition(e.RowIndex); object key = this.grid[row, grid.Binder.NameToColIndex("priKey")].CellValue; //use key to get object from hashtable object val = hash[key]; e.Style.CellValue = val; }

Brandon Richter
Replied On April 8, 2005 05:58 PM UTC

Clay, thanks for your response. If I understand you correctly, this creates a mapping between the unbound column entries and the bound column entries based on a key value. This allows me to lookup the unbound values for a row after the grid has been sorted. The unbound column data will not match the bound column data for each row after the grid has been sorted. Would it make more sense to add a column to the underlying datatable before it is bound to the grid? I don''t mind doing this as there will be no editing of data in the grid itself. The question then is how to programatically move the "extra" columns in the datatable to a particular column in the grid? I basically need to calculate and display a status column after I have filled my datatable, but I want it to appear immediately to the right of the row header in the grid. Of course, I need it to be sortable and moveable also. Thanks for your help.

Administrator [Syncfusion]
Replied On April 8, 2005 10:32 PM UTC

If the calculation you want to do can be expression in an DataColumn.Expression property, then simplest thing to do is to add a DataColumn to your DataTable setting its Expression property. Then this column will be displayed in the GridDataBoundGrid just like any other column in the DataTable. You can control the order of the columns in teh grid by explicitly adding GridBoundColumn objects to the grid.GridBoundColumns collection in the order you want to see them in the grid. Make sure you set the GridBoundColumn.MappingName property to be the ColumnName of the DataColumn. This is how the grid associates its columns with columns in the datatable. If what you want to do cannot be done in an Expression DataColumn, then instead of a unbound column, you can add a column to the DataTable and populate it directly, and have it show up in the grid. It is simpler to add the column before you set the grid''s Datasource. If you want to do it after you set the grid''s datasource, then you will also have to call grid.Binder.InitizializeColumns.


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.

Warning Icon 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.Close Icon