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

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
 
M

Miha Markic

Hi Eric,

You'll have to loop through all rows in DataView until you find yours.
 
A

Anders Borum

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.
 
E

Eric Harmon

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
 
M

Miha Markic

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top