Friday, October 19, 2012

How to Get the Selected Cells and Rows in the Windows Forms DataGridView Control


Here basically I am showing how to get selected cells/rows in DataGridView Control and use of IEnumerator while accessing them.



                DataGridViewSelectedRowCollection m = dataGrid_ZipList.SelectedRows;
                DataGridViewRow row;
 
                IEnumerator Enumerator = m.GetEnumerator();
                Enumerator.Reset();
                while (Enumerator.MoveNext())
                {
                    row = (DataGridViewRow)Enumerator.Current;
                    lstPostalCodes.Add(row.Cells["POSTAL_CODE"].Value.ToString());                   
                }

No comments:

Post a Comment