C# DATAGRIDVIEW FULL ROW SELECTION BUT GET SINGLE CELL VALUE

Goti Bandu

Total Post:119

Points:835
Posted by  Goti Bandu
C# 
C#
 9912  View(s)
Ratings:
Rate this:

I have a datagridview that is a full row select. How would I grab the data from only a certain cell no matter what cell in the row was clicked on since it highlights the entire row.

  1. jacob rasel

    Post:88

    Points:616
    Re: C# datagridview full row selection but get single cell value

    You can do like this......

         private void datagridview1_SelectionChanged(object sender, EventArgs e)
         {
             if (datagridview1.SelectedCells.Count > 0)
             {
                 int selectedrowindex = datagridview1.SelectedCells[0].RowIndex;
                 DataGridViewRow selectedRow = datagridview1.Rows[selectedrowindex];  
                  string a = Convert.ToString(selectedRow.Cells["you have to mention you cell  corresponding column name"].Value);           
             }
         }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!