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

GDBG. How can I add new columns in the grid and

Hello. I have dataset with two tables are related. Firstly, I want to hide header for Parent table. Furthe, I Added columns to the grid like this: GridHierarchyLevel quotes = gridDataBoundGrid1.Binder.AddRelation(dataset11.Relations[0].RelationName); GridHierarchyLevel root = gridDataBoundGrid1.Binder.RootHierarchyLevel; root.LayoutColumns(new string[] {"Portfolio", "-", "-", "-", "-", "-", "-", "-", "-"}); quotes.LayoutColumns(new string[]{"Symbol", "Compress", "Date", "Open", "High", "Low", "Close", "Volume"}); Now, I want to add new 4 columns Col1, Col2, Col3, Col4 to the nested table and I want to cover it with header "Added Columns". Please see example. This is must be before adding new columns: BeforeAdd_9425.zip And this is must be after adding new columns: AfterAdd_7751.zip Please draw attention , I need to add columns to nested table. Thanks a lot. Best Regards, Slava.

8 Replies

AD Administrator Syncfusion Team May 10, 2004 01:53 PM UTC

Attached is a sample of one way you can do this. It adds an exta row header, and provides teh header text in PrepareViewStyleInfo on demand. forum_addColumns_199.zip


SI Silenter May 12, 2004 03:31 AM UTC

Ok, Thanks. But, when Parent header is hidden I can''t resize columns of nested table. How can i fix it? Regards, Slava.


AD Administrator Syncfusion Team May 12, 2004 05:36 AM UTC

Try including the InsideGrid flag in the grid.ResizeColsBehavior flag. This should let you resize anywhere in the grid, not just on the first header row.


SI Silenter May 12, 2004 11:17 AM UTC

Ok, It works. Thanks. Slava.


SI Silenter May 13, 2004 11:25 AM UTC

Hi again. 1. I Binded dataGrid to datasource. 2. I Added new columns to datasource and grid. 3. And now I can''t type any data in the added columns. How can I fix it? You can test it. Run this example SyncDBGGrid_3180.zip And: 1. Click "Load Data". 2. Click "Add columns". 3. Now try to type anything to the added columns. Regards, Slava.


AD Administrator Syncfusion Team May 13, 2004 11:48 AM UTC

Those added columns are not in your datasource. That means that there is no storage allcated to save anything typed into those cells that don''t have columns in the underlying datasource. If you want to use unbound columns like this, then you will have to handle grid.Model.QueryCellInfo and grid.Model.SaveCellInfo. Additionally, you will have to allocate some storage object to hold the data. (maybe a Hashtable or DataTable or Array or ???) In your QueryCellInfo handler, based on e.ColIndex and e.RowIndex, you would retrieve the requested row and col value from you storage object, and set this value in e.Style.CellValue. In SaveCellInfo, you would go in the opposite direction, getting the value from e.Style.CellValue and storing it into your data storage based on e.RowIndex and e.ColIndex. You can see a sample of using unbound columns in this manner in Grid\Samples\DataBound\GDBGMultiHeader.


SI Silenter May 14, 2004 03:30 AM UTC

Hi, Sorry, But you are not right. Added columns exist in my datasource. for(Int32 i = 0; i < 4; i++) { dataset11.Quote.Columns.Add("asd" + i.ToString(), typeof(Double)); } m_Root.LayoutColumns(new string[] {"Portfolio", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-"}); m_Quotes.LayoutColumns(new string[]{"Symbol", "Compress", "Date", "Open", "High", "Low", "Close", "Volume", "asd0", "asd1", "asd2", "asd3"});


AD Administrator Syncfusion Team May 14, 2004 04:31 AM UTC

I am sorry. You are correct, I missed that code. Here is your sample back modified to allow the changes to take. To get the grid to be aware of the added columns, the code essentially rebinds the grid. I also added to lines like grid.BeginUpdate/EndUpdate and grid.Binder.SuspendBinding/ResumeBinding. The rebinding code fits into the scheme you were trying to use. Another option entirely might be to use the DataSet.Merge command to add the additional columns to the table. I did not actually try this, so I am not sure if you would still have to do this rebinding to get this to work also. (You may as you are actually changing the child table in the relation.) SyncDBGGrid_1814.zip

Loader.
Live Chat Icon For mobile
Up arrow icon