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

RowFormatting ?

4 Answers 302 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mateo
Top achievements
Rank 1
Mateo asked on 06 Sep 2007, 10:11 PM
I need to format a row depending on a state of the DataBoundItem and i'm trying to use the RowFormatting event.

In some cases i need to set the font of the row to italic and in some other cases i need to hide it from the user.

here is my code

void radGridViewSearchResults_RowFormatting(object sender, RowFormattingEventArgs e)

{

GridViewRowInfo gvri = e.RowElement.RowInfo;

myobject obj = gvri.DataBoundItem as myobject;

if (obj.IsDeleted)

{

gvri.IsVisible = false;

return;

}

if (obj.IsModified || obj.IsNew)

gvri.VisualElement.Font = new Font(gvri.VisualElement.Font.FontFamily, gvri.VisualElement.Font.SizeInPoints, FontStyle.Italic);

if (obj.IsOnError)

gvri.VisualElement.BackColor = Color.Red;

}

The problem is that the rows that should be hidden are still showing up and the ones that should be in red are not?
I've check the state of my objects and they are correct.

I've also remarked that the RowFormatting event is called tice for each item?

What is the correct way of hidding a row from the grid and customize its style?

thanks

4 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 07 Sep 2007, 12:32 PM
Hello Mateo,

The RowFormatting event is fired when row content needs to be updated from within the grid. So, if you changed some field in your business object, you must call the GridElement.Update function in order to provoke RowFormatting event:

this.radGridView1.GridElement.Update(false);

This will be not necessary if your DataSource implements IBindingList interface and your business objects implement IEditableObject or INotifyPropertyChanged.

The RowFormatting event is fired for every grid row that supports row formatting. Because of this, you must check if your DataBoundItem is really an instance of myobject.

The property IsVisible of GridViewRowInfo can not be set from RowFormatting event. In this event you can only set properties regarding the visual appearance of a row element.
 

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mateo
Top achievements
Rank 1
answered on 07 Sep 2007, 01:06 PM
Ok thanks.

so how can i hide a row from being displayed in the grid?
0
Mateo
Top achievements
Rank 1
answered on 07 Sep 2007, 01:29 PM
this is not working

gvri.VisualElement.BackColor = Color.Red;

only when i select the line it becomes red, when i leave it, it returns white??


0
Jack
Telerik team
answered on 07 Sep 2007, 03:34 PM
Hi Mateo,

You can hide a row by setting its IsVisible property to false. This can be done anytime except during processing of RowFormatting event:

this.radGridView1.Rows[5].IsVisible = true;

The problem with BackColor is that by default the DrawFill property of GridRowElement is set to false. For most themes DrawFill is true only when the row is selected. So, your code must look something like this:

gvri.VisualElement.BackColor = Color.Red;
gvri.VisualElement.DrawFill = true;


 
Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
GridView
Asked by
Mateo
Top achievements
Rank 1
Answers by
Jack
Telerik team
Mateo
Top achievements
Rank 1
Share this question
or