Sunday, 13 April 2014

selected row in datagridview c#

Getting the seltected rwo in the data grid from code behind in C#.

Suppose you give the name of data grid as dg;

Just do compy and paste of the below code you will get the row selected;

   public class EmplyeeBAO
        private ArrayList GetSelectedRows(DataGrid dg)
   ArrayList al = new ArrayList();
   CurrencyManager cm = (CurrencyManager)this.
                                    BindingContext[dg.DataSource, dg.DataMember];
   DataView dv = (DataView)cm.List;
   for(int i = 0; i < dv.Count; ++i)
     if(dg.IsSelected(i)) // find out the selected rwo
   return al;

No comments:

Post a Comment