NewRow(), Rows.Insert and not fired CellFormatting/RowFormatting Events

5 posts, 0 answers
  1. Anton Tokar
    Anton Tokar avatar
    1 posts
    Member since:
    Oct 2012

    Posted 03 Feb 2009 Link to this post

    Hi,
    I'm using the RadGridView to programmatically insert new rows at specific locations. To accomplish this I use the following code:

    var rowIndex = someNumber;
    var row = Grid.Rows.NewRow();
    Grid.Rows.Insert(rowIndex, row);

    Though the row is visibly inserted in the grid by the following code, neither the values assigned to the cells of this row are displayed (though the assignment doesn't throw any exceptions), nor are the defined CellFormatting or RowFormatting events of the grid are fired.

    If I use the following code instead all events and assignments are fine:

    var row = Grid.Rows.AddNew();

    I need an insert and not and add.

    Please advise.

    Best regards,
    Anton
  2. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 03 Feb 2009 Link to this post

    Hi Anton,

    Thank you for reporting this issue.

    I confirm that it exists in our latest release - Q3 2008 SP2. We will try to address it in one of our next versions. I have added points to your account for the report.

    You can use directly the API of the underlying data source to work around the issue. For example if you are using a BindingList, you should just call the Insert method and create a new instance of your business object.

    I hope this helps. Don't hesitate to contact us if you need further assistance.

    Kind regards,
    Jack
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Hugo
    Hugo avatar
    8 posts
    Member since:
    Jan 2009

    Posted 07 Feb 2009 Link to this post

    Hi,

    I am having a similar problem. I might be doing something wrong since I just started playing around with raddatagrid. In my case, I am inserting a user control via radHostItem. 

    1. first I, of course, set the datasource property (on form_load)
    radGridView1.DataSource = _localList;

    (_locallist, above, is a implementing System.ComponentModel.BindingList< MyBusinessObject  >)

    2) On CellFormatting I add my user control.
    private void radGridView1_CellFormatting_1(object sender, CellFormattingEventArgs e)
            {
    if (e.CellElement.ColumnInfo is GridViewDataColumn && !(e.CellElement.RowElement is GridTableHeaderRowElement))
                {
                    // do this only for column 1 and when no controls are added to the cell already.                        
                    if (e.CellElement.Children.Count > 0 || e.CellElement.ColumnIndex != 1)
                        return;

                    int j = e.CellElement.RowIndex;
                    MyBusinesClass MyBusinessObject = new MyBusinesClass();
                    RadHostItem i = new RadHostItem(MyBusinessObject );
                    e.CellElement.Children.Add(i);
                    e.CellElement.RowInfo.Height = MyBusinessObject .Height;
                    e.CellElement.ColumnInfo.Width = MyBusinessObject .Width;   
                }
    }

    Then, I insert a row like this (using my datasource):

            private void button1_Click(object sender, EventArgs e)
            {
                //this.radGridView1.Rows.Insert(0,radGridView1.Rows.NewRow());
                _localList.Insert(0, new Check());
            }

    The row gets inserted but the Height is not being set correctly. Apparently it is being set to the default one.

    I will appreciate your help.
  5. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 09 Feb 2009 Link to this post

    Hello Hugo,

    Thank you for writing.

    Your code should work and I was not able to reproduce the issue using several tests. Could you please send us your application so we can investigate and address any potential issue.

    Thank you in advance for your understanding and cooperation.

    All the best,
    Jack
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Hugo
    Hugo avatar
    8 posts
    Member since:
    Jan 2009

    Posted 14 Feb 2009 Link to this post

    I was able to achieve what I want by setting the height for all rows in the forms_load event.

    Thank you.
Back to Top
UI for WinForms is Visual Studio 2017 Ready