User (Old forums)MemberDecember 22, 2008 at 10:41 amPost count: 23064
I have looked through examples without any results, so here goes.
Can I add a sub-row to a grid that does not mean I have to create groups, new sub-grids, ect?
I simply want a structure where both the main item, and it’s children refers to the same column configuration as the main grid has, and there should not be any group titles or similar, simply something like this:
– Item 1
– – Item 1 subitem 1
– – Item 1 subitem 2
– Item 2
– Item 3
– – Item 3 subitem 1
All items are of the same type, therefore has the same columns, there just needs to be a plus next to Item 1, Item 2 and Item 3 to open their sub item.
Can this be done?
Imported from legacy forums. Posted by Brian (had 1437 views)User (Old forums)MemberDecember 22, 2008 at 3:56 pmPost count: 23064
You have no choice but to use a master/detail scenario for this.
If your data is not in a relational DB, you will need to feed the data manually to the grid.
The detail grids can be configured so they have only one column, with the header row hidden, with no spacing, so it appears as you described. Here is an example of what you need to do if you do every thing in code (in the designer it would be a bit different because the grid creates a whole bunch of things automatically when it is dropped on the form) :
private void Form1_Load( object sender, EventArgs e )
GridControl grid = new GridControl();
this.Controls.Add( grid );
grid.Dock = DockStyle.Fill;
grid.InitializingDetailGrid += new InitializingDetailGridEventHandler( grid_InitializingDetailGrid );
ColumnManagerRow headerRow = new ColumnManagerRow();
grid.FixedHeaderRows.Add( headerRow );
Column col = new Column( “Column 1”, typeof( string ) );
grid.Columns.Add( col );
DetailGrid detailGrid = new DetailGrid();
detailGrid.TopMargin.Height = 1;
detailGrid.BottomMargin.Height = 0;
Column detailCol = new Column( “Column 1”, typeof( string ) );
detailGrid.Columns.Add( detailCol );
grid.DetailGridTemplates.Add( detailGrid );
//Add 2 master rows
for( int i = 0; i < 2; i++ )
Xceed.Grid.DataRow row = grid.DataRows.AddNew();
row.Cells[ 0 ].Value = “Item “ + i.ToString();
void grid_InitializingDetailGrid( object sender, InitializingDetailGridEventArgs e )
//Add rows to the detail girds depending on the master row
if( e.Grid.ParentDataRow.Cells[ 0 ].Value.ToString() == “Item 0” )
for( int i = 1; i < 3; i++ )
Xceed.Grid.DataRow row = e.Grid.DataRows.AddNew();
row.Cells[ 0 ].Value = “sub item “ + i.ToString();
for( int i = 3; i < 6; i++ )
DataRow row = e.Grid.DataRows.AddNew();
row.Cells[ 0 ].Value =
“sub item “ + i.ToString();
Imported from legacy forums. Posted by André (had 624 views)User (Old forums)MemberMay 12, 2010 at 3:10 pmPost count: 23064
Is there any way to add the detail grid data outside of the event callback? I don’t mean have the event callback call another method, I mean have another addDetailGridRow() method that uses that handle and adds a row to the detail grid later in your program (such as when a user clicks a button).
Basically I have overridden GridControl, DetailGrid, DataRow, and DataCell to hold some local variables and make adding data easier. It all works when I add detail grids from the InitializingDetailGridEvent callback, but when I try and access the DetailGrids later they do not show up. If I call gridControl1.DataRows.DetailGrids.Count I can see all the rows I added exist, they just don’t show up on the grid. Is there some update I need to be calling? Some redraw method I failed to override?
Imported from legacy forums. Posted by Mac (had 260 views)User (Old forums)MemberMay 13, 2010 at 10:39 amPost count: 23064
It’s actually pretty easy to do, you just have to watch for pitfalls. If you call gridControl.UpdateDetailGrids(); it seems to erase the data, so you might perceive no changes, but really you are adding rows then they are being removed. So beware the UpdateDetailGrids() command.
Imported from legacy forums. Posted by Mac (had 1176 views)
- You must be logged in to reply to this topic.