c# - How to scroll through each Datagrid Item on button click wpf -


i have datagrid , 2 , down buttons user can scroll through each datagrid item on button click; either or down. how go doing this? have tried selectedindex doesn't seem work datagrid.

examplecode:

    private void btndowncheckedmedication_click(object sender, routedeventargs e)     {         if (medicationcheckedindatagrid.selectedindex > 0)         {             medicationcheckedindatagrid.selectedindex = medicationcheckedindatagrid.selectedindex - 1;         }     }      private void btnupcheckedmedication_click(object sender, routedeventargs e)     {         medicationcheckedindatagrid.selectedindex = medicationcheckedindatagrid.selectedindex + 1;     } 

you had it... use selecteditem instead:

private void btndowncheckedmedication_click( object sender, routedeventargs e ) {     if(datagrid.selectedindex > 0 ) {         datagrid.selecteditem = datagrid.items[datagrid.selectedindex - 1];     } }  private void btnupcheckedmedication_click( object sender, routedeventargs e ) {     if(datagrid.selectedindex < datagrid.items.count - 1) {         datagrid.selecteditem = datagrid.items[datagrid.selectedindex + 1];     } } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -