RowFormatting ?

5 posts, 0 answers
  1. Mateo
    Mateo avatar
    17 posts
    Member since:
    Aug 2007

    Posted 06 Sep 2007 Link to this post

    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

  2. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 07 Sep 2007 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Mateo
    Mateo avatar
    17 posts
    Member since:
    Aug 2007

    Posted 07 Sep 2007 Link to this post

    Ok thanks.

    so how can i hide a row from being displayed in the grid?
  5. Mateo
    Mateo avatar
    17 posts
    Member since:
    Aug 2007

    Posted 07 Sep 2007 Link to this post

    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??


  6. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 07 Sep 2007 Link to this post

    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready