Finding a row by ID - data view is not sorted by ID

  • Thread starter Thread starter Eric Harmon
  • Start date Start date
E

Eric Harmon

Hi,

I have a bit of an issue that I don't know how to deal with. I have a
dataview connected to a datagrid. I don't know exactly how the dataview
might be sorted at any point in time, as the user can click on the grid
headers to change the sort order.

Regardless of how the grid/dataview is sorted, I have a routine that I call,
which adds a row to the underlying table, using MyTable.NewRow(),
MyTable.AddRow(), etc. The row shows up in the grid in the correct order,
but I want to set focus to the newly added row. I know the ID (primary key)
of the row just added, but the grid might be sorted by name, city, state,
etc.

What's the best way to find the index of the newly added item in the
dataview/grid regardless of sort order, so I can set it as the current row?

Thanks in advance for any help you can provide...

-Eric
 
Sounds quite ineffective. What about using the .Select() method on the
DataTable/DataView? If there's an index on the DataTable, and you're using a
strongly typed dataset, a FindBy<columnname>() method available.
 
Anders,

There *is* a FindByID on the table, and I can call that, which will return
me the row, but then I still have the problem of locating it in the dataview
so I can position myself to it in the grid...

-Eric
 
There *is* a FindByID on the table, and I can call that, which will return
me the row, but then I still have the problem of locating it in the dataview
so I can position myself to it in the grid...

Exactly.
 
Back
Top