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

Group expand collapse

2 Answers 199 Views
GridView
This is a migrated thread and some comments may be shown as answers.
IT Development
Top achievements
Rank 1
IT Development asked on 30 Jul 2009, 08:48 AM

Hello,

 

Having some problems with the radgridview.

In the CellFormatting event i add some backgroundcolors and a progressbar to the grid.

All works fine here.

 

But when I collapse and expand the groups in the grid. The progressbar is moving up and down a copple a rows ( not corresponding with the data in the rows).

 

Any suggestions?

 

Kind regards,

 

Tim van Rooijen

 

 

private void radGridViewProductie_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)

        {

            // exclude header element in the data column                      

            if (e.CellElement.ColumnInfo is GridViewDataColumn && !(e.CellElement.RowElement is GridTableHeaderRowElement))

            {

                GridViewDataColumn column = (GridViewDataColumn)e.CellElement.ColumnInfo;

                GridViewRowInfo gvri = e.CellElement.RowInfo;

                if (gvri != null)

                {

                    SchrapView Sv = (SchrapView)gvri.DataBoundItem;

                    if (Sv != null)

                    {

                        //Voor percentage velden worden weergegeven met een progressbar

                        if (column.FieldName == "VorigeBewerking.PercentageCompleet" || column.FieldName == "Nacalculatie.PercentageCompleet")

                        {

                            // check if the progress bar is already added to the cell                          

                            if (e.CellElement.Children.Count > 0)

                                return;

                            RadProgressBarElement element = new RadProgressBarElement();

                            e.CellElement.Children.Add(element);

                            element.StretchHorizontally = true;

                            element.StretchVertically = true;

                            // extract the value in the cell, convert it to a value

                            // usable in the progress bar element and assign it to the

                            // progress bar Value1 and Text properties

                            int discountPercentage = Convert.ToInt32(e.CellElement.Text);

                            if (discountPercentage > 100)

                            {

                                element.Value1 = 100;

                            }

                            else

                            {

                                element.Value1 = discountPercentage;

                            }

                           element.Text = discountPercentage.ToString() + "%";                

                        

                        }

 

                        if (column.FieldName == "Indicator")

                        {

                            if (!Sv.AchterGrondKleur.IsEmpty)

                            {

                                e.CellElement.BackColor = Sv.AchterGrondKleur;

                                e.CellElement.DrawFill = true;

                            }

                            else

                            {

                                e.CellElement.BackColor = Color.Transparent;

                                e.CellElement.BackColor2 = Color.Transparent;

                                e.CellElement.DrawFill = true;

                            }

                        }

                    }

                }


2 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 30 Jul 2009, 10:10 AM
Hello Tim,

I think the issue is that you initialize the progress bar only upon creation. You should initialize it every time when CellFormatting is fired. Here is the modified code:

private void radGridViewProductie_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e) 
    // exclude header element in the data column                       
    if (e.CellElement.ColumnInfo is GridViewDataColumn && !(e.CellElement.RowElement is GridTableHeaderRowElement)) 
    { 
        GridViewDataColumn column = (GridViewDataColumn)e.CellElement.ColumnInfo; 
        GridViewRowInfo gvri = e.CellElement.RowInfo; 
        if (gvri != null
        { 
            SchrapView Sv = (SchrapView)gvri.DataBoundItem; 
            if (Sv != null
            { 
                //Voor percentage velden worden weergegeven met een progressbar 
                if (column.FieldName == "VorigeBewerking.PercentageCompleet" || column.FieldName == "Nacalculatie.PercentageCompleet"
                { 
                    RadProgressBarElement element = null
                    if (e.CellElement.Children.Count == 0) 
                    { 
                        element = new RadProgressBarElement(); 
                        e.CellElement.Children.Add(element); 
                        element.StretchHorizontally = true
                        element.StretchVertically = true
                    } 
                    else 
                    { 
                        element = (RadProgressBarElement)e.CellElement.Children[0]; 
                    } 
 
                    // extract the value in the cell, convert it to a value 
                    // usable in the progress bar element and assign it to the 
                    // progress bar Value1 and Text properties 
                    int discountPercentage = Convert.ToInt32(e.CellElement.Text); 
                    if (discountPercentage > 100) 
                    { 
                        element.Value1 = 100; 
                    } 
                    else 
                    { 
                        element.Value1 = discountPercentage; 
                    } 
                   element.Text = discountPercentage.ToString() + "%";                 
                } 
                if (column.FieldName == "Indicator"
                { 
                    if (!Sv.AchterGrondKleur.IsEmpty) 
                    { 
                        e.CellElement.BackColor = Sv.AchterGrondKleur; 
                        e.CellElement.DrawFill = true
                    } 
                    else 
                    { 
                        e.CellElement.BackColor = Color.Transparent; 
                        e.CellElement.BackColor2 = Color.Transparent; 
                        e.CellElement.DrawFill = true
                    } 
                } 
            } 
        }  
    } 

I hope this helps. If the issue continues to appear, please send me your application and I will try to find a solution.

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

Kind 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
IT Development
Top achievements
Rank 1
answered on 30 Jul 2009, 10:18 AM
it works!

Thanks for the support

Kind regards,

Tim van Rooijen
Tags
GridView
Asked by
IT Development
Top achievements
Rank 1
Answers by
Jack
Telerik team
IT Development
Top achievements
Rank 1
Share this question
or