JJ
Jisha Joy
Syncfusion Team
March 25, 2011 07:25 AM UTC
Hi Alex,
Thank you for using Syncfusion products.
You need to handle the QueryCellInfo event to achieve the desired behavior. Please refer to the code,
void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
//other codes
if (e.ColIndex == 1)
{
GridBoundRecordState state = this.gridDataBoundGrid1.Binder.GetRecordStateAtRowIndex(e.RowIndex);
if (state.HasChildList && state.ChildCount == 0)
{
e.Style.CellType = "Static";
e.Style.Enabled = false;
e.Style.Clickable = false;
e.Style.Text = "";
e.Style.BackColor = SystemColors.Control;
}
}
}
Regards,
Jisha
AF
Alex Feldman
March 25, 2011 05:36 PM UTC
Thank you, Jisha
Unfortunately the example doesn't work in my case: all rows pluses got hidden, even if row has nested rows.
I'm going to try to use my binding list structure to find out whether record has a "ChildCount > 0". It should work.
However if you know any other internal grid way to achive the result it would help.
Alex Feldman.
JJ
Jisha Joy
Syncfusion Team
March 30, 2011 11:00 AM UTC
Hi Alex,
Could you please provide us a sample showing the issue?.
Regards,
Jisha
AF
Alex Feldman
March 30, 2011 04:09 PM UTC
Hi Jisha,
I have attached the example.
Click the button on the top would assign DataSource to the grid.
The last row has nested row. If the code from your example disabled ("Model_QueryCellInfo") you can see the nested rows.
Thank you,
Alex Feldman.
pushButtonTest_72d06937.zip
JJ
Jisha Joy
Syncfusion Team
March 31, 2011 08:42 AM UTC
Hi Alex,
Please find the following modified code for QueryCellInfo to solve the issue,
private void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if (e.ColIndex == 1)
{
GridBoundRecordState state = this.gridDataBoundGrid1.Binder.GetRecordStateAtRowIndex(e.RowIndex);
if (state !=null && state.HasChildList && state.ChildCount == 0)
{
int count;
if (state.Position >= state.Table.Count)
{
count = 0;
}
else
{
this.gridDataBoundGrid1.BeginUpdate();
this.gridDataBoundGrid1.ExpandAtRowIndex(e.RowIndex);
count = state.ChildCount;
this.gridDataBoundGrid1.CollapseAtRowIndex(e.RowIndex);
this.gridDataBoundGrid1.EndUpdate();
}
if (count == 0)
{
e.Style.CellType = "Static";
e.Style.Enabled = false;
e.Style.Clickable = false;
e.Style.Text = "";
e.Style.BackColor = SystemColors.Control;
}
}
}
}
Regards,
Jisha
AF
Alex Feldman
March 31, 2011 01:21 PM UTC
Thank you Jisha,
It works for the test case.
Unfortunately I could not use it, since it's broken if any of the column is sorted.
In my workaround I use
int pos = gdbView.Binder.RowIndexToListManagerPosition(e.RowIndex);
which return correct position in CurrencyManager.
But I don't know how to get correct GridBoundRecordState.
Could you help?
Thank you,
Alex Feldman.
AF
Alex Feldman
March 31, 2011 01:33 PM UTC
I have added SortableBindingList into my test project.
You can check the solution attached.
pushButtonTest2_db4c132c.zip
JJ
Jisha Joy
Syncfusion Team
April 5, 2011 07:18 AM UTC
Hi Alex,
To get the record index of the hierarchical GridDataBoundGrid from its absolute row index, you can make use of ‘RowIndexToListManagerPosition()’ method to achieve this. This method returns the zero based row index of the underlying data source.
//in CelldoubleClick event
void gridDataBoundGrid1_CellDoubleClick(object sender, GridCellClickEventArgs e)
{
int level = this.gridDataBoundGrid1.Binder.GetRecordStateAtRowIndex(e.RowIndex).LevelIndex;
int index = this.gridDataBoundGrid1.Binder.RowIndexToListManagerPosition(e.RowIndex);
MessageBox.Show("Level: " + level.ToString() + ", RecordIndex: " + index.ToString());
}
Regards,
Jisha
AF
Alex Feldman
April 5, 2011 05:28 PM UTC
Thank you, Jisha,
Can you please answer my original question?
How I can hide "plus" buttons in case there are no nested rows.
The code in your example does not work for sorted GDBG.
Thank you,
Alex Feldman.
AF
Alex Feldman
April 11, 2011 02:48 PM UTC
Hi Jisha,
The example you attach reference the initial example, that doesn't work at all!
I have attached the latest example for you.
And here the steps to replicate the issue:
1. Click "button1". Binding is set.
2. Verify that record with ID=4 has nested rows: expand and than collapse the row.
3. Double click to the header of "ID" or "Name" column. Make sorting reverse, so record id=4 is the first row.
Plus button is not displayed in this case.
Could you please tell is there workaround for this?
Thank you,
Alex Feldman.
PlusButtonTest3_7a72668.zip
AF
Alex Feldman
April 18, 2011 01:03 PM UTC
Salute Jisha,
Unfortunately, your example doesn't work.
I have performed the following steps in your example.
1. Delete all children of parentName0 using "Delete current row". (There were 2 children).
2. Sort "ParentName" by double clicking the header. Button is still displayed incorrectly for parenName0 row, when it resorted to be the last and the first again.
Less important but when sorting is performed, all rows are collapsing.
Could you please provide workaround?
JJ
Jisha Joy
Syncfusion Team
April 28, 2011 11:41 AM UTC
Hi Alex,
Sorry for the delay in getting back to you. We are currently working on this and will update you by tomorrow/.
Regards,
Jisha
AF
Alex Feldman
May 3, 2011 02:55 PM UTC
Thank you Jisha,
I'm waiting.
Alex Feldman.
RC
Rajadurai C
Syncfusion Team
May 9, 2011 08:56 AM UTC
Hi Alex,
We regret for the delay in getting back to you.
To remove the plus/minus icon getting displayed after sorting for rows that doesn't have child rows, you can handle the following code in QueryCellInfo event.
if (e.RowIndex > this.gridDataBoundGrid1.Model.Rows.HeaderCount && e.ColIndex == 1)
{
GridBoundRecordState state = gridDataBoundGrid1.Binder.GetRecordStateAtRowIndex(e.RowIndex);
GridHierarchyLevel level = gridDataBoundGrid1.Binder.GetHierarchyLevel(state.LevelIndex);
IList list=null;
if(state.Table.Count > state.Position)
list = GetChildList(level.Relation, state.Table[state.Position]);
bool newHasChildList = list != null && list.Count > 0;
if (newHasChildList)
{
e.Style.CellType = "DataBoundRowExpandCell";
}
else
{
e.Style.CellType = "RowHeader";
e.Style.Text = string.Empty;
}
}
Here is the modified sample for your reference.
http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=UpdatableCollectionBaseExpandGrid_Modified-902323328.zipTo retain the expanded state after sorting applied, you would have to handle respective settings in the sample. Please find the sample below that achieves the same.
http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=SortExpanded12098648.zipRegards,
Rajadurai
AF
Alex Feldman
May 9, 2011 01:10 PM UTC
Thank you Jisha!
Wow, it looks like it's working!
RC
Rajadurai C
Syncfusion Team
May 10, 2011 03:36 AM UTC
Hi Alex,
Thanks for your update.
Regards,
Rajadurai