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

RadGridView - Add new record from a button instead of pressing insert

3 Answers 381 Views
GridView
This is a migrated thread and some comments may be shown as answers.
MarkBr
Top achievements
Rank 2
MarkBr asked on 09 Jan 2009, 08:03 AM
Hi,
I would like to know:
a) How to insert a new row in the RadGridView by clicking on a button rather than pressing the insert key.

b) How can i also insert multiple rows using the button? Currently when pressing the insert key twice does not insert 2 new rows.

Regards,
Mark.

3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 12 Jan 2009, 04:52 PM
Hello MarkBr,

The Insert key is intended to toggle between visible and hidden state of the new row. So pressing it multiple times will just toggle visibility multiple times.

The workaround is to add multiple empty records to the ItemsSource of the grid on pressing a button. Later the user may focus and edit the empty cells.
I am preparing a sample project for you to demonstrate how this may be done. I'll send it to you later today.

Regards,
Pavel Pavlov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Gavin Bryan
Top achievements
Rank 1
answered on 14 Jan 2009, 01:33 AM
Hi Pavel

I would also be interested in this project to see how this is done. Is it also possible to have a copy of the sample project ?

Thanks

Gavin
0
Hristo Deshev
Telerik team
answered on 17 Jan 2009, 12:33 PM
Hi Gavin Bryan,

I am attaching Pavel's project. It binds to an ObservableCollection of Customer objects and upon clicking the Add Customers button inserts five empty objects. RadGridView picks those up and displays them in empty rows:

private void Add5Rows() 
    ObservableCollection<Customer> data = (ObservableCollection<Customer>) this.RadGridView1.ItemsSource; 
    for (int i = 0; i < 4; i++) 
    { 
        Customer blankCustomer = new Customer() { CustomerID = -1 }; 
        data.Add(blankCustomer); 
        pendingCustomers.Add(blankCustomer); 
    } 
 
private void AddCustomers_Click(object sender, RoutedEventArgs e) 
    Add5Rows(); 
 

The code also keeps track of newly-inserted customers by storing them in the pendingCustomers collection. Those customers are sent to the server whenever the user clicks the Save button:

private void SaveNewCustomers_Click(object sender, RoutedEventArgs e) 
    SavePendingCustomers(); 
 
 
private void SavePendingCustomers() 
    foreach (var Customer in this.pendingCustomers) 
    { 
        client.AddCustomerAsync(Customer); 
    } 
 
    this.pendingCustomers.Clear(); 
 


Sincerely yours,
Hristo Deshev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
MarkBr
Top achievements
Rank 2
Answers by
Pavel Pavlov
Telerik team
Gavin Bryan
Top achievements
Rank 1
Hristo Deshev
Telerik team
Share this question
or