Page view counter
How to add the Row to DataGrid programatically in silverlight 2 Beta 2? ? ?
Last post 08-22-2008 12:31 AM by balukr54. 9 replies.
Sort Posts:
06-19-2008 8:26 AM
How to add the Row to DataGrid programatically in silverlight 2 Beta 2? ? ?

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.

Regards,
Pradeep.

deepsilverlight

Loading...
Joined on 06-19-2008
Posts 17
06-19-2008 8:31 AM
Re: How to add the Row to DataGrid programatically in silverlight 2 Beta 2? ? ?

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

----------------------------------------------
http://leeontech.wordpress.com/

lee_sl

Loading...
Joined on 05-09-2008
Posts 409
06-19-2008 8:35 AM
Re: How to add the Row to DataGrid programatically in silverlight 2 Beta 2? ? ?

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 ? ?

Regards,
Pradeep.

deepsilverlight

Loading...
Joined on 06-19-2008
Posts 17
06-19-2008 8:39 AM
Re: Re: How to add the Row to DataGrid programatically in silverlight 2 Beta 2? ? ?

what is the itemssource for the datagrid.

----------------------------------------------
http://leeontech.wordpress.com/

lee_sl

Loading...
Joined on 05-09-2008
Posts 409
06-19-2008 8:45 AM
Re: Re: How to add the Row to DataGrid programatically in silverlight 2 Beta 2? ? ?

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. . .  

 

Regards,
Pradeep.

deepsilverlight

Loading...
Joined on 06-19-2008
Posts 17
06-19-2008 9:09 AM
Marked as Answer
Re: Re: Re: How to add the Row to DataGrid programatically in silverlight 2 Beta 2? ? ?

add item to the list and reset the ItemsSource

dg.ItemsSource = null;

dg.ItemsSource = source;

----------------------------------------------
http://leeontech.wordpress.com/

lee_sl

Loading...
Joined on 05-09-2008
Posts 409
06-20-2008 12:05 AM
Marked as Answer
Re: Re: Re: How to add the Row to DataGrid programatically in silverlight 2 Beta 2? ? ?

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?

jasonxz

Loading...
Joined on 04-17-2007
Arlington, TX
Posts 522
06-20-2008 1:41 AM
Marked as Answer
Re: Re: How to add the Row to DataGrid programatically in silverlight 2 Beta 2? ? ?

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.

Yifung Lin [MSFT]

yifung

Loading...
Joined on 03-25-2008
Redmond, WA
Posts 92
06-20-2008 1:43 AM
Marked as Answer
Re: Re: Re: How to add the Row to DataGrid programatically in silverlight 2 Beta 2? ? ?

jasonxz:

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

Yifung Lin [MSFT]

yifung

Loading...
Joined on 03-25-2008
Redmond, WA
Posts 92
08-22-2008 12:31 AM
Re: Re: Re: Re: How to add the Row to DataGrid programatically in silverlight 2 Beta 2? ? ?
i too need to add a empty row on a btn click.. is there any way.???
balukr54

Loading...
Joined on 08-14-2008
India
Posts 56
Microsoft Communities