HOW TO FIND A ROW IN DATAGRIDVIEW AND UPDATE IT

Jeet Verma

Total Post:110

Points:776
Posted by  Jeet Verma
C# 
C#
 937  View(s)
Ratings:
Rate this:

I can show data in GridView, now I need find a row with user input in DataGridView so the cursor moves to this row, get this row and update the field (I want updated fields in a textbox on the form , after update), show updated row in datagridview and cursor move to next row automaticaly

Can someone help me?
  1. Pravesh Singh

    Post:412

    Points:2888
    Re: How to find a Row in Datagridview and update it

    Hi Jeet,


    let's say you'r binded data artifact (class is MyData)

    public class MyData

       public string Name {get;set;}

       public string Address {get;set}

    }

    so yuo have somewhere a collection of of MyData like List<MyData>

    List<MyData> myDataList = new List<MyData>();

    and do somewhere in the code, I presume, something like this:

    dataGrid.DataSource=myDataList

    Now, yo want to find some row on DataGrid, but you really want is to find a data. So, make a query over the myDataList to find MyData object of interest, let's say like this

    var foundMyData = from data in myDataList where (. condition..) select data;

    We found the data we interested in, so no let-\'s make it selected on UI. So find the index of the foundMyData in the list and select corresponding row on the grid.

    If you use Sorting, or View so the data visible on the screen can be filtered or sorted, you need to consider that "transformations" too, naturally.

Answer

NEWSLETTER

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