Home > Prsnl References > Customization on WPF ListView

Customization on WPF ListView

If  some one is planning to simply bind a list of datas to a listview in WPF its pretty easy and straight forward. But today i came through a case where i need a listbox that supports Sorting , Inline Editting and Save the chages to Db once i finish the inline edit .

I started one by one  1. Sorting and Inline Editting  > Using the logic or idea from this blog http://tech.pro/tutorial/857/wpf-tutorial-using-the-listview-part-3-in-place-edit

2. Saving the changes after finish the edit operation to Db – Add a new event to the textbox where you want to edit the data and do actions on that event

LostFocus=”textWordDescription_LostFocus” Tag=”{Binding}”

             string newtext = ((TextBox)sender).Text;
BindedObject selected = ((TextBox)sender).Tag as BindedObject;
updateDetails(selected.Id,selected);

Then next challenge is  want to sort my datas in ascending order . The following code solves that issue

  private void Sort(string sortBy, ListSortDirection direction)
{
ICollectionView dataView =
CollectionViewSource.GetDefaultView(wordBankListView.ItemsSource);
dataView.SortDescriptions.Clear();
SortDescription sd = new SortDescription(sortBy, direction);
dataView.SortDescriptions.Add(sd);
dataView.Refresh();
}

Next Challenge is with selection . By default i want to select an item in listbox (Its  pretty easy thing . just set selectedvalue ). But i need to handle the position of scrollviewer as well . If 100 items in listbox and i selected an item starts with letter z then thae item is in bottom of list , So using this code i make sure the scrollviewer position is closer to selected wordSystem.Windows.Controls.Primitives.Selector selector = wordBankListView;
(selector as ListBox).ScrollIntoView(selector.SelectedItem);

Advertisements
Categories: Prsnl References Tags: ,
  1. June 23, 2013 at 6:46 pm

    Ahaa, its good conversation on the topic of this piece of writing at this place at this blog, I have read all that, so now me also commenting here.

  2. September 5, 2013 at 8:57 am

    I blog quite often and I genuinely appreciate your content.
    Your article has rewlly peaked my interest. I’m going to take a note of
    your site and keep checking for new information about once per week.

    I opted in for your RSS feed too.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: