Google Search

Google
 

Sunday, November 30, 2008

code to select the specified gridview row WPF

In WPF gridview when we have click on edit or delete button, the button functionality is executed but the current row is not selected by default. to select the end user selected row in wpf gridview the itemcontainerstyle should be implemented for the listview.


Below is the code for select the row when user selects the delete button in wpf gridview

Step1: create an itemcontainerstyle for listview

"ListView.ItemContainerStyle"
Style TargetType="ListViewItem"
Setter Property="HorizontalContentAlignment" Value="Stretch" /
EventSetter Event="GotFocus" Handler="Item_GotFocus"/
/Style
/ListView.ItemContainerStyle"



step2:

private void Item_GotFocus(Object sender ,RoutedEventArgs e)
{
ListViewItem item;
item = (ListViewItem) sender;
MyListView.SelectedItem = item.DataContext;
}

No comments: