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

Adding a row programmaticaly?

1 Answer 130 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Leopard Supportperson
Top achievements
Rank 1
Leopard Supportperson asked on 15 Nov 2007, 01:06 AM
Hi,
I bind a List<T> to the grid and get the items displayed properly. When I want to add a new item into the list of items, I do that from the code - so, a user presses 'Add' button, and in the code I actually add an instance of type T into the list. However, the grid does not get updated with that new row. This is the code I use to bind:

List<T> myList = whatever;
GridInstance.DataSource = myList;

When I add a new item:

myList.Add(new T());

If I check GridInstance.DataSource right after I add an instance into the list, then I can see that the DataSource refers to the updated list, but the UI stays the same...

What should I do to update the UI in this case? Thanks!

1 Answer, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 15 Nov 2007, 12:20 PM
Hello Leopard Supportperson,

Thank you for writing us.

If you use a DataSet or a DataTable, RadGridView will automatically update itself if you make changes directly to the data source (adding, removing or changing data). 

However If you use custom business objects, such as List<T>, you must implement the IBindingList and the  INotifyPropertyChanged interfaces in order to notify the grid about any changes in your data source. A simple way to do this is to use BindingList<T> instead of List<T>.

Don't hesitate to contact us if you have other questions.

Greetings,
Jack
the Telerik team

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