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

How to select a child row in hirarchical grid

3 Answers 375 Views
GridView
This is a migrated thread and some comments may be shown as answers.
santhosh
Top achievements
Rank 2
santhosh asked on 22 May 2009, 03:04 PM
Hi,
        I am using gridview in winForm to display Parent and child records. My application doesn't have user intraction so every thing should happen at run time.
My application should behave.
1. Parent grid first row should be selected and expanded (This is working for me), then child grid first row should be selected (row by row should be selected till end of the child grid) once all the rows are over the parent grid first row should collapse and second row of parent grid should expand the same process should continue till end of parent grid rows.(This is not happening for me)
-- Here another condition is like parent grid row (which is expanded) should remain selected while child grid selection is scrolling.

2. Another requirement
  -- how to insert the image in child grid (Imagecolumn)

Thanks
  Santhosh
 

3 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 25 May 2009, 11:17 AM
Hello santhosh,

Regarding your questions:

1.  As I understand, you want to select all rows from the child views. Currently row selection works on a view basis. This means that you can select rows from only one view at a time. We will consider changing our selection mechanism in our future versions. You could use a hidden column to store selection information and change the row color inside the RowFormatting event. If you need further advise with this issue, I will be glad to help.

2. When using an image column, it tries to get the image from the underplaying data source. However, you can change this image manually when handling CellFormatting event. Here is a sample:

void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) 
    if (e.CellElement.ViewTemplate.Parent != null && e.CellElement.ColumnInfo is GridViewImageColumn) 
    { 
        e.CellElement.Image = Resources.green; 
    } 

I hope this helps. If you need further assistance, don't hesitate to write us.

Regards,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
santhosh
Top achievements
Rank 2
answered on 26 May 2009, 12:35 PM

Thanks for your reply.

In order to complete my application atleast can I highlight the parent row(current expanded row) by changing the background color and let the child grid should highlight row by row automatically. is it possible? if yes how can I do it?

to select parent and child grid row I have written code as shown

 

With

radgrdviewTeam

 

 

        If .RowCount > 0 Then

 

 

            If miParentRowIndex < .RowCount Then

 

                .Select() ' This will activate the parent grid(I think).

 

                If miChildRowIndex = 0 Then

 

                    .SelectionMode = GridViewSelectionMode.FullRowSelect

                    .MasterGridViewTemplate.Rows(miParentRowIndex).IsSelected =

True 

 

                    .MasterGridViewTemplate.Rows(miParentRowIndex).IsCurrent =

True

 

 

                    .MasterGridViewTemplate.Rows(miParentRowIndex).IsExpanded = True

 

 

                    .MasterGridViewTemplate.Rows(miParentRowIndex - 1).IsExpanded = False

 

 

                     miParentRowIndex += 1

 

 

                End If

 

 

         End If

 

 

         If miParentRowIndex < .RowCount Then

 

 

                 With .MasterGridViewTemplate.ChildGridViewTemplates(0)

 

 

                        If .RowCount > 0 Then

 

 

                             If miChildRowIndex < .RowCount Then

 

 

                                 .Rows(miChildRowIndex).IsCurrent = True

 

 

                                 .Rows(miChildRowIndex).IsSelected = True

 

 

                                 miChildRowIndex += 1

 

 

                            End If

 

 

                             If miChildRowIndex = .RowCount Then

 

 

                                 miChildRowIndex = 0

 

 

                            End If

 

 

                     End If

 

 

             End With

 

 

      End If
End With
This is placed under timer control, every second this code is going to execute. First time parent first row is highlighting (selecting) but once parent grid is expanded then child grid first row should highlight(select). This is not happening. how can I achieve this?
Note: If parent row is loosing its focus no problem atleast can we change its background? in order to show current row as selected.
even I tried to change the background color, it is not allowing to change. Is it because of custom theme which i have used.

If have different logic to achieve this, please send, that will be a grate help.

Thanks
  Santhosh
 

0
Jack
Telerik team
answered on 27 May 2009, 10:59 AM
Hello santhosh,

You can change the background of an expanded row when handling RowFormatting event. You should check its IsExpanded property. Here is a sample:

void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e) 
    if (e.RowElement is GridDataRowElement && e.RowElement.RowInfo.IsExpanded) 
    { 
        e.RowElement.DrawFill = true
        e.RowElement.BackColor = Color.AliceBlue; 
        e.RowElement.GradientStyle = GradientStyles.Solid; 
    } 
    else 
    { 
        e.RowElement.ResetValue(RadItem.BackColorProperty); 
        e.RowElement.ResetValue(LightVisualElement.DrawFillProperty); 
        e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty); 
    } 

You can't change the row color by iterating over the rows and changing their properties. However, you can handle RowFormatting event and check whether the row belongs to a child view, then change its background color. You could use the Tag property to store information whether the row is selected and change this on CellClick event. Consider this sample:

foreach (GridViewRowInfo row in radGridView1.MasterGridViewTemplate.ChildGridViewTemplates[0].Rows) 
    row.Tag = true
     
void radGridView1_CellClick(object sender, GridViewCellEventArgs e) 
    if (this.radGridView1.CurrentRow.ViewTemplate.Parent != null
    { 
        if (this.radGridView1.CurrentRow.Tag == null
        { 
            this.radGridView1.CurrentRow.Tag = true
        } 
        else 
        { 
            this.radGridView1.CurrentRow.Tag = null
        } 
    } 
 
void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e) 
    if (e.RowElement.ViewTemplate.Parent != null
    { 
        if (e.RowElement.RowInfo.Tag != null
        { 
            e.RowElement.DrawFill = true
            e.RowElement.BackColor = Color.AliceBlue; 
            e.RowElement.GradientStyle = GradientStyles.Solid; 
        } 
        else 
        { 
            e.RowElement.ResetValue(RadItem.BackColorProperty); 
            e.RowElement.ResetValue(LightVisualElement.DrawFillProperty); 
            e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty); 
        } 
    } 

I hope this works for you, nevertheless that it is not true selection. If you have any further questions, I will be glad to help.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
santhosh
Top achievements
Rank 2
Answers by
Jack
Telerik team
santhosh
Top achievements
Rank 2
Share this question
or