This is a migrated thread and some comments may be shown as answers.

Hierarchical Grid row selection

3 Answers 170 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rama
Top achievements
Rank 1
Rama asked on 18 Sep 2008, 03:13 PM
I would like to enable/disable button's on my form based on whether the user clicks the master row or the child row.
I am trying the following code, but this does not seem to work correctly in all the conditions.

What is the correct way to do this?
-------------------
GridViewSelectedRowsCollection selectedRows = this.rgResults.SelectedRows;
foreach (GridViewRowInfo selectedRow in selectedRows)
{
GridViewDataRowInfo selectedDataRow = selectedRow as GridViewDataRowInfo;
if (selectedDataRow != null)
{
bool isMaster = (selectedDataRow.ViewTemplate.ChildGridViewTemplates.Count == 1);
if (isMaster)
{
//Enable button1
//Disable button2
}
else
{
//Enable button2
//Disable button1

}

3 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 19 Sep 2008, 04:07 PM
Hi Rama,

Thank you for this question.

You can check whether the Parent property of the corresponding GridViewTemplate is null. This will ensure that the row is from the master template. Check the following code snippet:

GridViewSelectedRowsCollection selectedRows = this.rgResults.SelectedRows; 
foreach (GridViewRowInfo selectedRow in selectedRows) 
    GridViewDataRowInfo selectedDataRow = selectedRow as GridViewDataRowInfo; 
    if (selectedDataRow != null
    { 
        bool isMaster = (selectedDataRow.ViewTemplate.Parent == null); 
        if (isMaster) 
        { 
            //Enable button1 
            //Disable button2 
        } 
        else 
        { 
            //Enable button2 
            //Disable button1 
        }  
    } 


Should you have any questions, don't hesitate to ask.

Sincerely yours,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Rama
Top achievements
Rank 1
answered on 19 Sep 2008, 05:22 PM
Thanks for fix.
I see another problem now, SelectionChanged event does not get fired when we click the rows in the following order.

Click 'MasterGrid' Row - SelectionChanged event fires
Click 'ChildGrid' Row - SelectionChanged event fires
Click the same above 'MasterGrid' Row - SelectionChanged event does not fire
Click the same above 'ChildGrid' Row - SelectionChanged event does not fire

How we can we avoid this and have a consistent behaviour of SelectionChanged event.

I tried using the Click event instead but the selectedRows does not seem to change in the above case.

One more problem is that once a master grid row is expanded then this row remains expanded even if the grid is refreshed again.


Thanks
Rama
0
Jack
Telerik team
answered on 23 Sep 2008, 04:36 PM
Hm. Indeed, the SelectionChanged event isn't fired in this situation - we will address this issue in one of our upcoming releases. I have updated your Telerik points for reporting this.

You could process the CellClick event to work around this issue. Consider the following code snippet:

GridViewRowInfo cachedCurrentRow; 
 
void radGridView1_CellClick(object sender, GridViewCellEventArgs e) 
    if (this.radGridView1.CurrentRow != cachedCurrentRow) 
    { 
        cachedCurrentRow = this.radGridView1.CurrentRow; 
        // ... 
    }             


Please note that by default the expanded child views remain in this state until you explicitly change their state. You can collapse a child view by setting the IsExpanded property of the parent row to false. You can use the following code snippet:

GridViewDataRowInfo row = this.radGridView1.CurrentRow as GridViewDataRowInfo; 
if (this.radGridView1.CurrentView == this.radGridView1.GridElement) 
    row.IsExpanded = false

I hope this helps. Do not hesitate to contact me if you need further assistance.
 

Regards,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Rama
Top achievements
Rank 1
Answers by
Jack
Telerik team
Rama
Top achievements
Rank 1
Share this question
or