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.

TreeGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

42386 Mar 28,2006 05:48 AM Apr 13,2006 03:43 AM Windows Forms 27
loading
Tags: GridControl
Kai
Asked On March 28, 2006 05:48 AM

Hi, is it possible to do something like the VirtTreeGrid from the samples using DataBoundGrid? In my dataset, some rows have parent-child relationship, so I want to display them in a tree like structure. So for other row that doesn''t have a parent/child, I want to display them just like a normal row. How can we do that? or would that be easier if we use the GridGroupingControl?? If so, how? Many Thanks.

Administrator [Syncfusion]
Replied On March 28, 2006 08:03 AM

Hi Kai, We are having KB articles related to this issue. Please refer to this KB article which shows how to display records in the required manner as you have mentioned for GridDataBoundGrid. In the GridGroupingControl, please refer to this KB article to have this functionality. Let us know if this helps. Best regards, Madhan.

Administrator [Syncfusion]
Replied On March 28, 2006 08:06 AM

Hi Kai, Sorry for the broken link GridDataBoundGrid [ http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=330 ] GridGroupingControl [ http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=251 ] Best regards, Madhan.

Kai
Replied On March 28, 2006 10:10 PM

Thanks Madhan, I am trying the DataBoundGrid method in the KB article. And it is exactly what I am looking for. However, my datatable has a self join parent-child relationship. For example: employeeId, name, phone, managerEmployeeId How can I define such relationship in the DataRelation?? or is there a trick that I can do to achieve that (in DataBoundGrid)? Many thanks. >Hi Kai, > >Sorry for the broken link > >GridDataBoundGrid [ http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=330 ] >GridGroupingControl [ http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=251 ] > >Best regards, >Madhan.

Administrator [Syncfusion]
Replied On March 29, 2006 02:04 AM

Hi Kai, Please refer to the Attachment section in KB article, you can find a sample which explains how to achieve this process. Here is code snippet. gridDataBoundGrid1.Binder.SetDataBinding(ds, "ParentTable"); GridHierarchyLevel childrenLevel = gridDataBoundGrid1.Binder.AddRelation("Parent_Child"); childrenLevel.ShowHeaders = false; gridDataBoundGrid1.Binder.RootHierarchyLevel.ShowHeaders = true; Let us know if this helps. Best regards, Madhan.

Kai
Replied On March 29, 2006 02:31 AM

Hi Madhan, yes, I have seen the sample. But in the sample, the parent-child relationship is based on two tables. In my case, I only have one data table. The parent-child relationship is depended indicated in a column of a row. (i.e a self-join table relationship) example: DataTable dt = new DataTable(); dt.Columns.Add("employeeId"); dt.Columns.Add("name"); dt.Columns.Add("phone"); dt.Columns.Add("managerEmployeeId"); dt.Rows.Add(new object[]{"1","john","12345678",""}); dt.Rows.Add(new object[]{"2","peter","45678901","1"}); dt.Rows.Add(new object[]{"3","mary","55678901",""}); So my question is, how do I define such DataRelation? I tried, ds.Relations.Add("Relation1", dt.Columns["employeeId"], dt.Columns["managerEmployeeId"], false); but it gave me a runtime error. >Hi Kai, > >Please refer to the Attachment section in KB article, you can find a sample which explains how to achieve this process. Here is code snippet. > >gridDataBoundGrid1.Binder.SetDataBinding(ds, "ParentTable"); >GridHierarchyLevel childrenLevel = gridDataBoundGrid1.Binder.AddRelation("Parent_Child"); >childrenLevel.ShowHeaders = false; >gridDataBoundGrid1.Binder.RootHierarchyLevel.ShowHeaders = true; > >Let us know if this helps. > >Best regards, >Madhan.

Kai
Replied On March 29, 2006 03:02 AM

Nevermind, my bad. Here is what I did, works now. dataTable1.Rows.Add(new object[]{"1","2","3","4","2"}); dataTable1.Rows.Add(new object[]{"2","2","3","4","6"}); dataTable1.Rows.Add(new object[]{"3","2","3","4","6"}); dataTable1.Rows.Add(new object[]{"4","2","3","4","6"}); dataTable1.Rows.Add(new object[]{"5","2","3","4","6"}); dataTable1.Rows.Add(new object[]{"6","2","3","4",""}); dataSet1.Relations.Add("Relation1", dataTable1.Columns["Column1"], dataTable1.Columns["Column5"], false); GDBG.Text = "Master-View"; GDBG.Binder.SetDataBinding(dataSet1, "Table1"); Syncfusion.Windows.Forms.Grid.GridHierarchyLevel childrenLevel = GDBG.Binder.AddRelation("Relation1"); childrenLevel.ShowHeaders = false; GDBG.Binder.RootHierarchyLevel.ShowHeaders = true; Sorry for the trouble. >Hi Madhan, > >yes, I have seen the sample. But in the sample, the parent-child relationship is based on two tables. In my case, I only have one data table. The parent-child relationship is depended indicated in a column of a row. (i.e a self-join table relationship) > >example: >DataTable dt = new DataTable(); >dt.Columns.Add("employeeId"); >dt.Columns.Add("name"); >dt.Columns.Add("phone"); >dt.Columns.Add("managerEmployeeId"); > >dt.Rows.Add(new object[]{"1","john","12345678",""}); >dt.Rows.Add(new object[]{"2","peter","45678901","1"}); >dt.Rows.Add(new object[]{"3","mary","55678901",""}); > >So my question is, how do I define such DataRelation? > >I tried, >ds.Relations.Add("Relation1", dt.Columns["employeeId"], dt.Columns["managerEmployeeId"], false); >but it gave me a runtime error. > > > > >>Hi Kai, >> >>Please refer to the Attachment section in KB article, you can find a sample which explains how to achieve this process. Here is code snippet. >> >>gridDataBoundGrid1.Binder.SetDataBinding(ds, "ParentTable"); >>GridHierarchyLevel childrenLevel = gridDataBoundGrid1.Binder.AddRelation("Parent_Child"); >>childrenLevel.ShowHeaders = false; >>gridDataBoundGrid1.Binder.RootHierarchyLevel.ShowHeaders = true; >> >>Let us know if this helps. >> >>Best regards, >>Madhan.

Administrator [Syncfusion]
Replied On March 29, 2006 04:40 AM

Hi Kai, We are glad that you got the issue solved by yourself. Thanks for sharing the information with us. Thanks for choosing Syncfusion products. Best regards, Madhan

Kai
Replied On March 29, 2006 05:26 AM

Hi Madhan, sorry to trouble you again. I have the following: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; namespace GGCTree { /// /// Summary description for Form2. /// public class Form2 : System.Windows.Forms.Form { private Syncfusion.Windows.Forms.Grid.GridDataBoundGrid GDBG; private System.Data.DataSet dataSet1; private System.Data.DataTable dataTable1; private System.Data.DataColumn dataColumn1; private System.Data.DataColumn dataColumn2; private System.Data.DataColumn dataColumn3; private System.Data.DataColumn dataColumn4; private System.Data.DataColumn dataColumn5; private System.Windows.Forms.Button button1; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form2() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // dataTable1.Rows.Add(new object[]{"1","2","3","4","2"}); dataTable1.Rows.Add(new object[]{"2","2","3","4",""}); dataTable1.Rows.Add(new object[]{"3","2","3","4","6"}); dataTable1.Rows.Add(new object[]{"4","2","3","4","6"}); dataTable1.Rows.Add(new object[]{"5","2","3","4","6"}); dataTable1.Rows.Add(new object[]{"6","2","3","4",""}); dataSet1.Relations.Add("Relation1", dataTable1.Columns["Column1"], dataTable1.Columns["Column5"], false); System.Data.DataView dv = new System.Data.DataView(dataTable1); dv.RowFilter = "Column5 = ''''"; GDBG.DataSource = dv; GDBG.Text = "Master-View"; //GDBG.Binder.SetDataBinding(dataSet1, "Table1"); Syncfusion.Windows.Forms.Grid.GridHierarchyLevel childrenLevel = GDBG.Binder.AddRelation("Relation1"); childrenLevel.ShowHeaders = false; GDBG.Binder.RootHierarchyLevel.ShowHeaders = true; GDBG.CellDrawn += new Syncfusion.Windows.Forms.Grid.GridDrawCellEventHandler(GDBG_CellDrawn); } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.GDBG = new Syncfusion.Windows.Forms.Grid.GridDataBoundGrid(); this.dataSet1 = new System.Data.DataSet(); this.dataTable1 = new System.Data.DataTable(); this.dataColumn1 = new System.Data.DataColumn(); this.dataColumn2 = new System.Data.DataColumn(); this.dataColumn3 = new System.Data.DataColumn(); this.dataColumn4 = new System.Data.DataColumn(); this.dataColumn5 = new System.Data.DataColumn(); this.button1 = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.GDBG)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataTable1)).BeginInit(); this.SuspendLayout(); // // GDBG // this.GDBG.AllowDragSelectedCols = true; this.GDBG.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.GDBG.DataSource = this.dataTable1; this.GDBG.Location = new System.Drawing.Point(8, 4); this.GDBG.Name = "GDBG"; this.GDBG.OptimizeInsertRemoveCells = true; this.GDBG.ShowCurrentCellBorderBehavior = Syncfusion.Windows.Forms.Grid.GridShowCurrentCellBorder.GrayWhenLostFocus; this.GDBG.Size = new System.Drawing.Size(464, 228); this.GDBG.SmartSizeBox = false; this.GDBG.SortBehavior = Syncfusion.Windows.Forms.Grid.GridSortBehavior.DoubleClick; this.GDBG.TabIndex = 0; this.GDBG.Text = "gridDataBoundGrid1"; this.GDBG.UseListChangedEvent = true; // // dataSet1 // this.dataSet1.DataSetName = "NewDataSet"; this.dataSet1.Locale = new System.Globalization.CultureInfo("en-US"); this.dataSet1.Tables.AddRange(new System.Data.DataTable[] { this.dataTable1}); // // dataTable1 // this.dataTable1.Columns.AddRange(new System.Data.DataColumn[] { this.dataColumn1, this.dataColumn2, this.dataColumn3, this.dataColumn4, this.dataColumn5}); this.dataTable1.TableName = "Table1"; // // dataColumn1 // this.dataColumn1.ColumnName = "Column1"; // // dataColumn2 // this.dataColumn2.ColumnName = "Column2"; // // dataColumn3 // this.dataColumn3.ColumnName = "Column3"; // // dataColumn4 // this.dataColumn4.ColumnName = "Column4"; // // dataColumn5 // this.dataColumn5.ColumnName = "Column5"; // // button1 // this.button1.Location = new System.Drawing.Point(203, 240); this.button1.Name = "button1"; this.button1.TabIndex = 1; this.button1.Text = "Add"; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form2 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(480, 273); this.Controls.Add(this.button1); this.Controls.Add(this.GDBG); this.Name = "Form2"; this.Text = "Form2"; ((System.ComponentModel.ISupportInitialize)(this.GDBG)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataTable1)).EndInit(); this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form2()); } private void GDBG_CellDrawn(object sender, Syncfusion.Windows.Forms.Grid.GridDrawCellEventArgs e) { if (e.ColIndex == 1) { int count = -1; if (!GDBG.CurrentCell.IsEditing) { Syncfusion.Windows.Forms.Grid.GridBoundRecordState state = GDBG.Binder.GetRecordStateAtRowIndex(e.RowIndex); count = state.ChildCount; //to get the valid child count, the row has to be expanded so the childlist is populated //here we do a ''silent'' expand if (!GDBG.IsExpandedAtRowIndex(e.RowIndex)) { GDBG.BeginUpdate(); GDBG.Model.SuspendChangeEvents(); GDBG.ExpandAtRowIndex(e.RowIndex); count = state.ChildCount; GDBG.CollapseAtRowIndex(e.RowIndex); GDBG.Model.ResumeChangeEvents(); GDBG.EndUpdate(); } } if (count == 0 || e.RowIndex == GDBG.Model.RowCount || GDBG.Binder.IsAddNew) { Brush brush = new SolidBrush(e.Style.BackColor); try { e.Graphics.FillRectangle(brush,e.Bounds); e.Cancel = true; } finally { brush.Dispose(); } } } } private void button1_Click(object sender, System.EventArgs e) { dataTable1.Rows.Add(new object[]{(dataTable1.Rows.Count +1) + "", "2", "3", "4", "6"}); } } } When the parent row is expanded and the user do the button click, it seems that the children of the parent didn''t get update immediately. Did I do something wrong?? Thanks. >Hi Kai, > >We are glad that you got the issue solved by yourself. Thanks for sharing the information with us. > >Thanks for choosing Syncfusion products. > >Best regards, >Madhan

Administrator [Syncfusion]
Replied On March 30, 2006 10:18 AM

Hi Kai, Thanks for the patience. Here is the sample demonstrates a way to resolve the issue, by Expanding and collapse the respective row and also it saves the expand states before the level is added, and restores them after the level is added. Let us know if this helps. Best regards, Madhan Sample : AddingChildRow_GDBG

Kai
Replied On April 6, 2006 04:34 AM

Thanks, it works as expected. However, I got 1 more question, is there any reason why a DataBoundGrid.Binder.AddRelation(relationName) will return null even though I am 100% sure that the relationName exists in the DataSet that it is binding from? I am using a code segment similar to the following: this.dataView.Table.DataSet.Relations.Add("Relation1", this.dataView.Table.Columns["Column1"], this.dataView.Table.Columns["Column5"], false); gridDataBoundGrid.DataSource = this.dataView; Syncfusion.Windows.Forms.Grid.GridHierarchyLevel childrenLevel = gridDataBoundGrid.Binder.AddRelation("Relation1"); But the childrenLevel is always null for some reason... did I do something wrong?? >Hi Kai, > >Thanks for the patience. Here is the sample demonstrates a way to resolve the issue, by Expanding and collapse the respective row and also it saves the expand states before the level is added, and restores them after the level is added. > >Let us know if this helps. > >Best regards, >Madhan > >Sample : AddingChildRow_GDBG

Kai
Replied On April 6, 2006 06:56 AM

It seems that if the gridDataBoundGrid is constructed in runtime, this line Syncfusion.Windows.Forms.Grid.GridHierarchyLevel childrenLevel = gridDataBoundGrid.Binder.AddRelation("Relation1"); is going to fail! for example: public GridDataBoundGrid GetGrid() { Syncfusion.Windows.Forms.Grid.GridDataBoundGrid _gg = new GridDataBoundGrid(); _gg.AllowDragSelectedCols = true; _gg.Location = new System.Drawing.Point(8, 4); _gg.Name = "GDBG"; _gg.OptimizeInsertRemoveCells = true; _gg.ShowCurrentCellBorderBehavior = Syncfusion.Windows.Forms.Grid.GridShowCurrentCellBorder.GrayWhenLostFocus; _gg.Size = new System.Drawing.Size(488, 225); _gg.SmartSizeBox = false; _gg.SortBehavior = Syncfusion.Windows.Forms.Grid.GridSortBehavior.DoubleClick; _gg.TabIndex = 0; _gg.Text = "gridDataBoundGrid1"; _gg.UseListChangedEvent = true; System.Data.DataView dv = new System.Data.DataView(dataTable1); dv.RowFilter = "Column5 = ''''"; dv.Table.DataSet.Relations.Add("Relation1", dv.Table.Columns["Column1"], dv.Table.Columns["Column5"], false); _gg.DataSource = dv; Syncfusion.Windows.Forms.Grid.GridHierarchyLevel childrenLevel = _gg.Binder.AddRelation("Relation1"); // will get NULL in here. childrenLevel.ShowHeaders = false; _gg.Binder.RootHierarchyLevel.ShowHeaders = true; _gg.CellDrawn += new Syncfusion.Windows.Forms.Grid.GridDrawCellEventHandler(GDBG_CellDrawn); _gg.Binder.OptimizeListChangedEvent = true; return _gg; } Any Idea how we can solve that?? Many Thanks. > >Thanks, it works as expected. >However, I got 1 more question, is there any reason why a DataBoundGrid.Binder.AddRelation(relationName) >will return null even though I am 100% sure that the relationName exists in the DataSet that it is binding from? > >I am using a code segment similar to the following: > >this.dataView.Table.DataSet.Relations.Add("Relation1", this.dataView.Table.Columns["Column1"], >this.dataView.Table.Columns["Column5"], false); > >gridDataBoundGrid.DataSource = this.dataView; > >Syncfusion.Windows.Forms.Grid.GridHierarchyLevel childrenLevel = gridDataBoundGrid.Binder.AddRelation("Relation1"); > >But the childrenLevel is always null for some reason... did I do something wrong?? > > >>Hi Kai, >> >>Thanks for the patience. Here is the sample demonstrates a way to resolve the issue, by Expanding and collapse the respective row and also it saves the expand states before the level is added, and restores them after the level is added. >> >>Let us know if this helps. >> >>Best regards, >>Madhan >> >>Sample : AddingChildRow_GDBG

Kai
Replied On April 6, 2006 07:10 AM

Attached is an example. > >It seems that if the gridDataBoundGrid is constructed in runtime, this line > >Syncfusion.Windows.Forms.Grid.GridHierarchyLevel childrenLevel = gridDataBoundGrid.Binder.AddRelation("Relation1"); >is going to fail! > >for example: > >public GridDataBoundGrid GetGrid() >{ >Syncfusion.Windows.Forms.Grid.GridDataBoundGrid _gg = new GridDataBoundGrid(); >_gg.AllowDragSelectedCols = true; > >_gg.Location = new System.Drawing.Point(8, 4); >_gg.Name = "GDBG"; >_gg.OptimizeInsertRemoveCells = true; >_gg.ShowCurrentCellBorderBehavior = Syncfusion.Windows.Forms.Grid.GridShowCurrentCellBorder.GrayWhenLostFocus; >_gg.Size = new System.Drawing.Size(488, 225); >_gg.SmartSizeBox = false; >_gg.SortBehavior = Syncfusion.Windows.Forms.Grid.GridSortBehavior.DoubleClick; >_gg.TabIndex = 0; >_gg.Text = "gridDataBoundGrid1"; >_gg.UseListChangedEvent = true; > >System.Data.DataView dv = new System.Data.DataView(dataTable1); >dv.RowFilter = "Column5 = ''''"; >dv.Table.DataSet.Relations.Add("Relation1", dv.Table.Columns["Column1"], dv.Table.Columns["Column5"], false); >_gg.DataSource = dv; > Syncfusion.Windows.Forms.Grid.GridHierarchyLevel childrenLevel = _gg.Binder.AddRelation("Relation1"); >// will get NULL in here. >childrenLevel.ShowHeaders = false; > _gg.Binder.RootHierarchyLevel.ShowHeaders = true; > >_gg.CellDrawn += new Syncfusion.Windows.Forms.Grid.GridDrawCellEventHandler(GDBG_CellDrawn); >_gg.Binder.OptimizeListChangedEvent = true; > >return _gg; >} > >Any Idea how we can solve that?? > >Many Thanks. > >> >>Thanks, it works as expected. >>However, I got 1 more question, is there any reason why a DataBoundGrid.Binder.AddRelation(relationName) >>will return null even though I am 100% sure that the relationName exists in the DataSet that it is binding from? >> >>I am using a code segment similar to the following: >> >>this.dataView.Table.DataSet.Relations.Add("Relation1", this.dataView.Table.Columns["Column1"], >>this.dataView.Table.Columns["Column5"], false); >> >>gridDataBoundGrid.DataSource = this.dataView; >> >>Syncfusion.Windows.Forms.Grid.GridHierarchyLevel childrenLevel = gridDataBoundGrid.Binder.AddRelation("Relation1"); >> >>But the childrenLevel is always null for some reason... did I do something wrong?? >> >> >>>Hi Kai, >>> >>>Thanks for the patience. Here is the sample demonstrates a way to resolve the issue, by Expanding and collapse the respective row and also it saves the expand states before the level is added, and restores them after the level is added. >>> >>>Let us know if this helps. >>> >>>Best regards, >>>Madhan >>> >>>Sample : AddingChildRow_GDBG

WindowsApplication127.zip

Administrator [Syncfusion]
Replied On April 6, 2006 09:27 AM

Hi Kai, You can avoid this problem by first initializing and adding the grid to the form and then assigning the GridHierarchyLevel. Sample : WindowsApplication1.zip Best regards, Madhan

Kai
Replied On April 10, 2006 06:30 AM

Hi, if I want to hide column 2 and column 5 in the grid. How can I do that? GridBoundColumn boundCol = new GridBoundColumn(); boundCol.HeaderText = "Column One"; boundCol.MappingName = "Column1"; GridBoundColumn boundCol3 = new GridBoundColumn(); boundCol3.HeaderText = "Column Three"; boundCol3.MappingName = "Column3"; GridBoundColumn boundCol4 = new GridBoundColumn(); boundCol4.HeaderText = "Column Four"; boundCol4.MappingName = "Column4"; GDBG.Binder.GridBoundColumns.Add(boundCol); GDBG.Binder.GridBoundColumns.Add(boundCol3); GDBG.Binder.GridBoundColumns.Add(boundCol4); Setting the GridBoundColumns seems only apply on the parent row but not the child rows. (And the data seems missing in the parent row.) Thanks a lot for your help!

Administrator [Syncfusion]
Replied On April 10, 2006 08:05 AM

Hi Kai, Try the below snippet code to see if that helps. this.GDBG.Model.Cols.Hidden["Column2"] = true; this.GDBG.Model.Cols.Hidden["Column5"] = true; Regards, Calvin.

Kai
Replied On April 10, 2006 11:34 PM

If I apply the hidden columns and also add the GridBoundColumns to the Grid, the display will get messed up. Anyway to fix this? GDBG.Model.Cols.Hidden["Column2"] = true; GDBG.Model.Cols.Hidden["Column5"] = true; GridBoundColumn boundCol = new GridBoundColumn(); boundCol.HeaderText = "Column One"; boundCol.MappingName = "Column1"; GridBoundColumn boundCol3 = new GridBoundColumn(); boundCol3.HeaderText = "Column Three"; boundCol3.MappingName = "Column3"; GridBoundColumn boundCol4 = new GridBoundColumn(); boundCol4.HeaderText = "Column Four"; boundCol4.MappingName = "Column4"; GDBG.Binder.GridBoundColumns.Add(boundCol); GDBG.Binder.GridBoundColumns.Add(boundCol3); GDBG.Binder.GridBoundColumns.Add(boundCol4); Thanks. >Hi Kai, > >Try the below snippet code to see if that helps. > >this.GDBG.Model.Cols.Hidden["Column2"] = true; >this.GDBG.Model.Cols.Hidden["Column5"] = true; > >Regards, >Calvin.

Kai
Replied On April 11, 2006 12:00 AM

Attached is a sample. >If I apply the hidden columns and also add the GridBoundColumns to the Grid, the display will get messed up. Anyway to fix this? > >GDBG.Model.Cols.Hidden["Column2"] = true; >GDBG.Model.Cols.Hidden["Column5"] = true; > >GridBoundColumn boundCol = new GridBoundColumn(); >boundCol.HeaderText = "Column One"; >boundCol.MappingName = "Column1"; > >GridBoundColumn boundCol3 = new GridBoundColumn(); >boundCol3.HeaderText = "Column Three"; >boundCol3.MappingName = "Column3"; > >GridBoundColumn boundCol4 = new GridBoundColumn(); >boundCol4.HeaderText = "Column Four"; >boundCol4.MappingName = "Column4"; > >GDBG.Binder.GridBoundColumns.Add(boundCol); >GDBG.Binder.GridBoundColumns.Add(boundCol3); >GDBG.Binder.GridBoundColumns.Add(boundCol4); > >Thanks. > > >>Hi Kai, >> >>Try the below snippet code to see if that helps. >> >>this.GDBG.Model.Cols.Hidden["Column2"] = true; >>this.GDBG.Model.Cols.Hidden["Column5"] = true; >> >>Regards, >>Calvin.

WindowsApplication128.zip

Administrator [Syncfusion]
Replied On April 11, 2006 03:39 AM

Hi Kai, Thanks for the sample. When the Cols.Hidden[colName] is used the GridBoundColumn can be avoided. Below is a code snippet that works fine. public Form1() { InitializeComponent(); dataTable1.Rows.Add(new object[]{"1","2","3","4","2"}); dataTable1.Rows.Add(new object[]{"2","2","3","4",""}); dataTable1.Rows.Add(new object[]{"3","2","3","4","6"}); dataTable1.Rows.Add(new object[]{"4","2","3","4","6"}); dataTable1.Rows.Add(new object[]{"5","2","3","4","6"}); dataTable1.Rows.Add(new object[]{"6","2","3","4",""}); this.GDBG = GetGDBG(); // parent row data missing!! // GridBoundColumn boundCol = new GridBoundColumn(); // boundCol.HeaderText = "Column One"; // boundCol.MappingName = "Column1"; // // GridBoundColumn boundCol2 = new GridBoundColumn(); // boundCol2.HeaderText = "Column Two"; // boundCol2.MappingName = "Column2"; // // GridBoundColumn boundCol3 = new GridBoundColumn(); // boundCol3.HeaderText = "Column Three"; // boundCol3.MappingName = "Column3"; // // GridBoundColumn boundCol4 = new GridBoundColumn(); // boundCol4.HeaderText = "Column Four"; // boundCol4.MappingName = "Column4"; // // GridBoundColumn boundCol5 = new GridBoundColumn(); // boundCol5.HeaderText = "Column Five"; // boundCol5.MappingName = "Column5"; // // this.GDBG.Binder.GridBoundColumns.Add(boundCol); // this.GDBG.Binder.GridBoundColumns.Add(boundCol2); // this.GDBG.Binder.GridBoundColumns.Add(boundCol3); // this.GDBG.Binder.GridBoundColumns.Add(boundCol4); // this.GDBG.Binder.GridBoundColumns.Add(boundCol5); GDBG.Binder.InternalColumns["Column1"].HeaderText = "Column One"; GDBG.Binder.InternalColumns["Column2"].HeaderText = "Column Two"; GDBG.Binder.InternalColumns["Column3"].HeaderText = "Column Three"; GDBG.Binder.InternalColumns["Column4"].HeaderText = "Column Four"; GDBG.Binder.InternalColumns["Column5"].HeaderText = "Column Five"; // GDBG.Model.Cols.Hidden["Column1"] = false; GDBG.Model.Cols.Hidden["Column2"] = true; // GDBG.Model.Cols.Hidden["Column3"] = false; // GDBG.Model.Cols.Hidden["Column4"] = false; GDBG.Model.Cols.Hidden["Column5"] = true; } Regards, Calvin.

Kai
Replied On April 11, 2006 04:05 AM

Thanks Calvin, However, if I do something like this, GDBG.Binder.InternalColumns["Column3"].StyleInfo.HorizontalAlignment = Syncfusion.Windows.Forms.Grid.GridHorizontalAlignment.Center; It seems that only the parent rows will get this style info but not the child rows. How can I apply the same style info to the children rows as well? >Hi Kai, > >Thanks for the sample. When the Cols.Hidden[colName] is used the GridBoundColumn can be avoided. Below is a code snippet that works fine. > > public Form1() > { > InitializeComponent(); > > dataTable1.Rows.Add(new object[]{"1","2","3","4","2"}); > dataTable1.Rows.Add(new object[]{"2","2","3","4",""}); > dataTable1.Rows.Add(new object[]{"3","2","3","4","6"}); > dataTable1.Rows.Add(new object[]{"4","2","3","4","6"}); > dataTable1.Rows.Add(new object[]{"5","2","3","4","6"}); > dataTable1.Rows.Add(new object[]{"6","2","3","4",""}); > > this.GDBG = GetGDBG(); > > // parent row data missing!! >// GridBoundColumn boundCol = new GridBoundColumn(); >// boundCol.HeaderText = "Column One"; >// boundCol.MappingName = "Column1"; >// >// GridBoundColumn boundCol2 = new GridBoundColumn(); >// boundCol2.HeaderText = "Column Two"; >// boundCol2.MappingName = "Column2"; >// >// GridBoundColumn boundCol3 = new GridBoundColumn(); >// boundCol3.HeaderText = "Column Three"; >// boundCol3.MappingName = "Column3"; >// >// GridBoundColumn boundCol4 = new GridBoundColumn(); >// boundCol4.HeaderText = "Column Four"; >// boundCol4.MappingName = "Column4"; >// >// GridBoundColumn boundCol5 = new GridBoundColumn(); >// boundCol5.HeaderText = "Column Five"; >// boundCol5.MappingName = "Column5"; >// >// this.GDBG.Binder.GridBoundColumns.Add(boundCol); >// this.GDBG.Binder.GridBoundColumns.Add(boundCol2); >// this.GDBG.Binder.GridBoundColumns.Add(boundCol3); >// this.GDBG.Binder.GridBoundColumns.Add(boundCol4); >// this.GDBG.Binder.GridBoundColumns.Add(boundCol5); > > GDBG.Binder.InternalColumns["Column1"].HeaderText = "Column One"; > GDBG.Binder.InternalColumns["Column2"].HeaderText = "Column Two"; > GDBG.Binder.InternalColumns["Column3"].HeaderText = "Column Three"; > GDBG.Binder.InternalColumns["Column4"].HeaderText = "Column Four"; > GDBG.Binder.InternalColumns["Column5"].HeaderText = "Column Five"; > >// GDBG.Model.Cols.Hidden["Column1"] = false; > GDBG.Model.Cols.Hidden["Column2"] = true; >// GDBG.Model.Cols.Hidden["Column3"] = false; >// GDBG.Model.Cols.Hidden["Column4"] = false; > GDBG.Model.Cols.Hidden["Column5"] = true; > > > } > >Regards, >Calvin.

Administrator [Syncfusion]
Replied On April 11, 2006 07:08 AM

Hi Kai, Try the below code to set the style of a column in the child level. GridHierarchyLevel childrenLevel = GDBG.Binder.GetHierarchyLevel(1); childrenLevel.InternalColumns["Column3"].StyleInfo.HorizontalAlignment = GridHorizontalAlignment.Center; Regards, Calvin.

Kai
Replied On April 11, 2006 11:22 PM

Thanks Calvin How do we arrage the columns'' display order using Internal Columns now? Many thanks. >Hi Kai, > >Try the below code to set the style of a column in the child level. > > GridHierarchyLevel childrenLevel = GDBG.Binder.GetHierarchyLevel(1); > childrenLevel.InternalColumns["Column3"].StyleInfo.HorizontalAlignment = GridHorizontalAlignment.Center; > >Regards, >Calvin.

Administrator [Syncfusion]
Replied On April 12, 2006 02:14 AM

Hi Kai, The Internal Columns can be arranged using LayoutColumns(GDBG.Binder.LayoutColumns(new string[]{"Column4","-","Column3","Column1"}); ). For more details on LayoutColumns please refer to the sample in \Syncfusion\Essential Studio\4.1.0.62\windows\Grid.Windows\Samples\DataBound\Hierarchical\ExpandGrid\ Below is a code snippet. public Form1() { InitializeComponent(); ............. .................. .......................... GDBG.Binder.InternalColumns["Column1"].HeaderText = "Column One"; GDBG.Binder.InternalColumns["Column2"].HeaderText = "Column Two"; GDBG.Binder.InternalColumns["Column3"].HeaderText = "Column Three"; GDBG.Binder.InternalColumns["Column4"].HeaderText = "Column Four"; GDBG.Binder.InternalColumns["Column5"].HeaderText = "Column Five"; GDBG.Model.Cols.Hidden["Column2"] = true; GDBG.Model.Cols.Hidden["Column5"] = true; GDBG.Binder.InternalColumns["Column3"].StyleInfo.HorizontalAlignment = GridHorizontalAlignment.Center; GridHierarchyLevel childrenLevel = GDBG.Binder.GetHierarchyLevel(1); childrenLevel.InternalColumns["Column3"].StyleInfo.HorizontalAlignment = GridHorizontalAlignment.Center; childrenLevel.LayoutColumns(new string[]{"Column4","-","Column3","Column1"}); GDBG.Binder.LayoutColumns(new string[]{"Column4","-","Column3","Column1"}); GDBG.Refresh(); } Regards, Calvin.

Administrator [Syncfusion]
Replied On April 12, 2006 02:19 AM

Hi Kai, Also the columns can be hidden using LayoutColumns instead of setting Model.Cols.Hidden["Column2"] = true; Below is a code snippet. // GDBG.Model.Cols.Hidden["Column2"] = true; // GDBG.Model.Cols.Hidden["Column5"] = true; GDBG.Binder.InternalColumns["Column3"].StyleInfo.HorizontalAlignment = GridHorizontalAlignment.Center; GridHierarchyLevel childrenLevel = GDBG.Binder.GetHierarchyLevel(1); childrenLevel.InternalColumns["Column3"].StyleInfo.HorizontalAlignment = GridHorizontalAlignment.Center; childrenLevel.LayoutColumns(new string[]{"Column4","Column3","Column1"}); GDBG.Binder.LayoutColumns(new string[]{"Column4","Column3","Column1"}); Regards, Calvin.

Kai
Replied On April 12, 2006 03:33 AM

Thanks Calvin. How can we get the DataRowView from the rowIndex in a DataBoundGrid with DataRelation?? >Hi Kai, > >Also the columns can be hidden using LayoutColumns instead of setting Model.Cols.Hidden["Column2"] = true; Below is a code snippet. > >// GDBG.Model.Cols.Hidden["Column2"] = true; >// GDBG.Model.Cols.Hidden["Column5"] = true; > > GDBG.Binder.InternalColumns["Column3"].StyleInfo.HorizontalAlignment = GridHorizontalAlignment.Center; > > GridHierarchyLevel childrenLevel = GDBG.Binder.GetHierarchyLevel(1); > childrenLevel.InternalColumns["Column3"].StyleInfo.HorizontalAlignment = GridHorizontalAlignment.Center; > > childrenLevel.LayoutColumns(new string[]{"Column4","Column3","Column1"}); > GDBG.Binder.LayoutColumns(new string[]{"Column4","Column3","Column1"}); > >Regards, >Calvin.

Kai
Replied On April 12, 2006 05:56 AM

This is what I am trying to do: private void GDBG_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e) { CurrencyManager cm = (CurrencyManager) GDBG.BindingContext[GDBG.DataSource]; DataRowView rowView = (DataRowView) cm.List[e.RowIndex]; if (((string) rowView.Row["Column3"]).Equals("3")) { e.Style.BackColor = Color.Wheat; } }

Administrator [Syncfusion]
Replied On April 12, 2006 06:40 AM

Hi Kai, Try the below code. private void GDBG_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e) { if(e.RowIndex > 0 && e.ColIndex >1) { GridBoundRecordState recordState = GDBG.Binder.GetRecordStateAtRowIndex(e.RowIndex); if(recordState.Position > -1 && recordState.Position < recordState.Table.Count) { DataRowView rowView = recordState.Table[recordState.Position] as DataRowView; if (((string) rowView.Row["Column3"]).Equals("3")) { e.Style.BackColor = Color.Wheat; } } } } Regards, Calvin.

Kai
Replied On April 13, 2006 03:43 AM

Thank you Calvin and Madhan. You two have solved all my problems. Thanks a lot for your help!

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.

;