lashapositioning in datatables

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi all

i have datatable with columns "id" and "name"

how can i set the position of cursor to the row where "id" equals to, for
example 5?

thanks
 
Hi lasha,

Are you trying to select a row in a datagrid which is bound to a datatable?
Or are you just trying to select a row from a datatable?

Rakesh
 
hi,
i'm trying to select a row from a datatable

Rakesh Rajan said:
Hi lasha,

Are you trying to select a row in a datagrid which is bound to a datatable?
Or are you just trying to select a row from a datatable?

Rakesh
 
Hi,

You could obtain the DataRow by using the DataTable.Select method, in which
you pass the select expression. In your case, the code might look like this:

DataRow[] myRows = myDataTable.Select("id=5");

HTH,
Rakesh
 
thank you, for your help,
but i have some different promlem

i want to show all rows in datagrid, but change the current row to the row
with specified id.

thanks again
 
Hi,

So you basically want to do this:
1. You want to select a row from a datatable which has a specific id value.
2. Once you get the row, you want that row to be the highlighted one in the
datagrid.

Right?

Strangely enough, I had the exact requirement in the opposite way :)

Rakesh
 
hi

i think u r only guy who helps me, :-)

yes u r right, this is what i want to do

so, can u help me

thank again
 
Hi lasha,

Sorry pal - I went to sleep...this time gap thing is one thing that get's
into way every now and then :)...I guess that's why many of the usual ppl
aren't posting....I don't even know whether you will read this post or not :(

AFAIK, there is no 'graceful' strightforward way of doing this...As i said
in my earlier post, the reverse method is quite simple to do. But in this
case, you need a workaround. The reason is that DataGrid.Select accepts only
an integer, and we need to figure out where in the datagrid our selected row
is currently placed. If the user changes the sort, the problem becomes all
the more significant because the position of our row will be different (as
per the sort expression).

In one of my previous projects, we had implemented a lil soluntion which
could be used here as well. The steps are as follows:

1. Programmatically add a new column to your datatable and fill in integers
starting from the first row to the last (1-n). Say, let the column name be
"myID".
2. Select the datarow you need using the select expression (DataTable.Select)
3. Find out the myID value of this row.
4. Use the datagrid.Select method to select that row passing in this integer.
5. Make sure that you handle the datagrid's sort event. When this happens,
you need to reset all the values in the myID column to the way they appear in
the grid. For this, you just access the defaultview of the datatable (which
is the sorted one) and then set the myID values with respect to that. With
this, you will be able to select rows even if the datagrid gets sorted :D

There might be better ways for doing this....I am still searching.

PS: If you want, I could post the code as well.

HTH,
Rakesh
 
Back
Top