none
How to add the Row to DataGrid programatically in silverlight 2 Beta 2? ? ?

    Question

  • Hi frnds,

                 In my application, when user click on the button  it should create a new row at the bottom of DataGrid . can we achieve this Programatically in silverlight 2 beta 2. ?  ?

     

    Thanx and Regards,

    Pradeep.

    Thursday, June 19, 2008 8:26 AM

Answers

  • add item to the list and reset the ItemsSource

    dg.ItemsSource = null;

    dg.ItemsSource = source;

    Thursday, June 19, 2008 9:09 AM
  • I would like to add 2 rows of summary information to the bottom of my DataGrid.  Technically, I could calculate the my summary values, instantiate a couple of fake objects and Add them to the ObservableCollection, but that seems like a hack.

    It would be nice to be able to create a footer, but I don't see that option anywhere.  Any other ideas?

    Friday, June 20, 2008 12:05 AM
  • As lee mentioned, you can use ObservableCollection<Data> instead of List<Data>.  Resetting the ItemsSource is an expensive operation it's better to use an ObservableCollection and add/remove from it.  You can simulate an empty row by adding an empty Data object to it.

    Friday, June 20, 2008 1:41 AM
  • I would like to add 2 rows of summary information to the bottom of my DataGrid.  Technically, I could calculate the my summary values, instantiate a couple of fake objects and Add them to the ObservableCollection, but that seems like a hack.

    It would be nice to be able to create a footer, but I don't see that option anywhere.  Any other ideas?

     There's no built in functionality for a footer, but you could re-template the DataGrid and put your own Custom footer in the Control

    Friday, June 20, 2008 1:43 AM

All replies

  • if you are using ObservableCollection, if you add item to the collection, it should automatically appear in the DataGrid

    Thursday, June 19, 2008 8:31 AM
  • Thanx for  ur reply. .

    I am not using Observablecollection. . When user clicks on the Button it should add a new row with empty textboxes in the datagrid for corresponding columns., , is it possible ? ? / How can we do that ? ?

    Thursday, June 19, 2008 8:35 AM
  • what is the itemssource for the datagrid.

    Thursday, June 19, 2008 8:39 AM
  • I am using the list as the item source for the datagrid. . .

    in page() i wrote this. . .  

    List
    <Data> source = new List<Data>();

    int itemsCount = 10;

    for (int i = 0; i < itemsCount; i++)

    {

    source.Add(
    new Data()

    {

    FirstName =
    "First",LastName = "Last",

    Age = i,

    Available = (i % 2 == 0)

    });

    }

    dg.ItemsSource = source;

     

    I have Defined data Class separately. . .  

     

    Thursday, June 19, 2008 8:45 AM
  • add item to the list and reset the ItemsSource

    dg.ItemsSource = null;

    dg.ItemsSource = source;

    Thursday, June 19, 2008 9:09 AM
  • I would like to add 2 rows of summary information to the bottom of my DataGrid.  Technically, I could calculate the my summary values, instantiate a couple of fake objects and Add them to the ObservableCollection, but that seems like a hack.

    It would be nice to be able to create a footer, but I don't see that option anywhere.  Any other ideas?

    Friday, June 20, 2008 12:05 AM
  • As lee mentioned, you can use ObservableCollection<Data> instead of List<Data>.  Resetting the ItemsSource is an expensive operation it's better to use an ObservableCollection and add/remove from it.  You can simulate an empty row by adding an empty Data object to it.

    Friday, June 20, 2008 1:41 AM
  • I would like to add 2 rows of summary information to the bottom of my DataGrid.  Technically, I could calculate the my summary values, instantiate a couple of fake objects and Add them to the ObservableCollection, but that seems like a hack.

    It would be nice to be able to create a footer, but I don't see that option anywhere.  Any other ideas?

     There's no built in functionality for a footer, but you could re-template the DataGrid and put your own Custom footer in the Control

    Friday, June 20, 2008 1:43 AM
  • i too need to add a empty row on a btn click.. is there any way.???
    Friday, August 22, 2008 12:31 AM