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

Formated row doesnt anchor on scrolling

4 Answers 94 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Thomas Schuster
Top achievements
Rank 1
Thomas Schuster asked on 11 Mar 2010, 10:37 AM
Hey Folks.

I'm currently stucked on a strange happening.

With the following code i'm formating a row, if cellvalue is changed.

private void gv_data_CellValueChanged(object sender, GridViewCellEventArgs e) 
        {             
            GridViewRowInfo r = e.Row; 
            ((GridCellElement)sender).RowElement.BackColor = Color.LightYellow; 
            ((GridCellElement)sender).RowElement.DrawFill = true;   
            r.Cells[1].Value = "1"
        } 

The BackColor appears to the row. Right so far.
But if im scrolling down then in the DataGridView, the formatting doesn't keep on its row, it's scrolling with.

Just want to highlight edited rows.

Any suggestions?

Kind regards, Tom


4 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 12 Mar 2010, 09:31 AM
Hi Thomas Schuster,

Thank you for contacting us. Visual elements are reused upon scrolling so you cannot set a color to a visual element and expect that it will be connected to a data element in a future moment. What you need to do is to use RowFormatting event as demonstrated in our online documentation. Please read this article and write me back if you are unsure how to implement the scenario.  

Kind regards,
Nick
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Thomas Schuster
Top achievements
Rank 1
answered on 12 Mar 2010, 11:38 AM
Now i used the your suggested method.
Same result, the formatting doesnt keep on its row :(

Here my new Code:

private void gv_data_CellValueChanged(object sender, GridViewCellEventArgs e) 
        {             
            GridViewRowInfo r = e.Row; 
            GridViewColumn c = e.Column; 
            xChange = true
            gv_data_RowFormatting(sender, new RowFormattingEventArgs(((GridCellElement)sender).RowElement));             
        } 
 

 private void gv_data_RowFormatting(object sender, RowFormattingEventArgs e) 
        { 
            if (!xChange) return
            e.RowElement.BackColor = Color.LightSteelBlue; 
            e.RowElement.DrawFill = true;   
 
            xChange = false
        } 


Did this as shown in your Tutorial

Regards, Tom
0
Thomas Schuster
Top achievements
Rank 1
answered on 17 Mar 2010, 10:22 AM
No more ideas?

is there any other way to highlight a row?

Regards, Tom
0
Nikolay
Telerik team
answered on 17 Mar 2010, 04:33 PM
Hello Thomas Schuster,

As my colleague Nick has mentioned, a RowElement is not binded to a data row, so when you scroll up and down you will lose the highlight of the edited rows and this highlight will go to other rows. The important thing is that you should have a condition opposing the 'if' where you should set the BackColor to the default value. In addition, you need to known whether the current data row of a RowElement is a modified row or not. You can use the Tag property of a row to set such flag:
void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e)
{
    if (e.RowElement.RowInfo.Tag != null && e.RowElement.RowInfo.Tag.ToString() == "Modified")
    {
        e.RowElement.BackColor = Color.Red;
        e.RowElement.DrawFill = true;  
  
    }
    else
    {
        if (e.RowElement.BackColor == Color.Red)
        {
            e.RowElement.ResetValue(LightVisualElement.DrawFillProperty);
            e.RowElement.ResetValue(VisualElement.BackColorProperty);
        }
    }
}
  
void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
{
    GridViewRowInfo r = e.Row;
    r.Tag = "Modified";
}

I hope this helps. If you have additional questions, feel free to contact me.

Regards,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Thomas Schuster
Top achievements
Rank 1
Answers by
Nick
Telerik team
Thomas Schuster
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or