ulduz114
ulduz114

Reputation: 1180

How to find a Row in Datagridview and update it

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?

Upvotes: 0

Views: 462

Answers (1)

Tigran
Tigran

Reputation: 62276

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.

Upvotes: 1

Related Questions