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

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

4 Answers 176 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Anton Tokar
Top achievements
Rank 1
Anton Tokar asked on 03 Feb 2009, 12:37 PM
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

4 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 03 Feb 2009, 07:01 PM
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.
0
Hugo
Top achievements
Rank 1
answered on 07 Feb 2009, 06:42 PM
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.
0
Jack
Telerik team
answered on 09 Feb 2009, 11:24 AM
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.
0
Hugo
Top achievements
Rank 1
answered on 15 Feb 2009, 03:14 AM
I was able to achieve what I want by setting the height for all rows in the forms_load event.

Thank you.
Tags
GridView
Asked by
Anton Tokar
Top achievements
Rank 1
Answers by
Jack
Telerik team
Hugo
Top achievements
Rank 1
Share this question
or