Search:
Namespaces
Discussions
.NET v1.1
Feedback
lashapositioning in datatables
Messages
Related Types
This message was discovered on
microsoft.public.dotnet.general
.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...
lasha (VIP)
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
Reply to this message...
Rakesh Rajan (VIP)
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
"lasha" wrote:
[Original message clipped]
Reply to this message...
lasha (VIP)
hi,
i'm trying to select a row from a datatable
"Rakesh Rajan" wrote:
[Original message clipped]
Reply to this message...
Rakesh Rajan (VIP)
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
"lasha" wrote:
[Original message clipped]
Reply to this message...
lasha (VIP)
hi
i'm also interestid in moving to the row in datagrid with specified id
thanks
"Rakesh Rajan" wrote:
[Original message clipped]
Reply to this message...
Rakesh Rajan (VIP)
Hi,
I think this is what you meant - you want only certain rows to be visible in
the datagrid.
For this, you just need to filter the datatable to obtain a dataview, and
bind the datagrid to this dataview (instead of the datatable).
You could create a
DataView
passing the datatable, filter expressions (eg.
"id=5"), and the rowstate using this constructor:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadataviewclassctortopic3.asp
HTH,
Rakesh
"lasha" wrote:
[Original message clipped]
Reply to this message...
lasha (VIP)
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
"Rakesh Rajan" wrote:
[Original message clipped]
Reply to this message...
Rakesh Rajan (VIP)
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
"lasha" wrote:
[Original message clipped]
Reply to this message...
lasha (VIP)
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
"Rakesh Rajan" wrote:
[Original message clipped]
Reply to this message...
Rakesh Rajan (VIP)
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
"lasha" wrote:
[Original message clipped]
Reply to this message...
System.Data.DataRow
System.Data.DataTable
System.Data.DataView
System.Windows.Forms.DataGrid
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com