Skip to main content

Microsoft Silverlight

Answered Question DataGrid column sortingRSS Feed

(0)

hotfrost
hotfrost

Member

Member

45 points

22 Posts

DataGrid column sorting

 Hello everyone,

 question;

is it possible to call sorting on one of the columns programatically in datagrid??

 one more question:

 how to change the itemssource for datagrid?

when i am switching for new itemssource the datagrid still displays the old data.

and there is no method Bind() to refresh the datagrid...

Thanks in advance!

 

Alex

 

meykih
meykih

Participant

Participant

876 points

213 Posts

Re: DataGrid column sorting

To your second question: Inside your datagrid columns you use databinding? Did you use INotifyPropertyChanged in your source data?

Regards,
Maike Ohlig

Please mark post as answer if it helped you

hotfrost
hotfrost

Member

Member

45 points

22 Posts

Re: Re: DataGrid column sorting

 no i didn't.. i resolved the problem first to set the datasource to null, and then again to bind it to datagrid.

 thanks,

 al

gunjanshah21
gunjansh...

Member

Member

526 points

88 Posts

Re: DataGrid column sorting

HotFrost:
is it possible to call sorting on one of the columns programatically in datagrid??

Yes, with Silverlight 3 Beta, you can use SortDescriptions to sort a column programatically, following sample should help:

using System.ComponentModel;

dataGrid.SortDescriptions.Add(new SortDescription("Property1" /*Bound to Column1*/, ListSortDirection.Ascending));

 You can even use this to have your columns initially sorted.

Gunjan [MSFT] 

 

yifung
yifung

Contributor

Contributor

3313 points

540 Posts

Microsoft
Answered Question

Re: DataGrid column sorting

For the items not updating, if you use an ObservableCollection as your ItemsSource

Yifung Lin [MSFT]

lijoputhuval
lijoputh...

Member

Member

108 points

51 Posts

Answered Question

Re: DataGrid column sorting

  Ya Observable Collection Is the Best Option To Set Item Source in DataGrid.

Try Like This..

public ObservableCollection<ClientListCommon> ClientList = new ObservableCollection<ClientListCommon>();

void multiSelectListServiceSoapClient_ClientListCompleted(object sender, SilverlightRD.MultiSelectListService.ClientListCompletedEventArgs e)

{

if (e.Error == null)

{

for (int i = 0; i < e.Result.Count; i++)

{

ClientList.Add(
new ClientListCommon() { RowId = Convert.ToInt32(e.ResultIdea[0]), CityName = e.ResultIdea[1].ToString()});

}

MyDataGrid.ItemsSource = ClientList ;

}

}

Please Mark As Answer if This Helps You

with Regards
Lijo
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities