Thanks for Bernie's response.
Hi Mauricio,
Assuming that you have both references to the DataTable and DataRow
objects, and the DataRow is in DataTable.Rows collection, you can also use
Ojbect.ReferenceEquals method to get the index. Here's an example:
private int FindIndex(DataTable dt, DataRow dr)
{
for(int i=0;i<dt.Rows.Count;i++)
if(Object.ReferenceEquals(dt.Rows[i], dr))
return i;
return -1;
}
For more information about Object.ReferenceEquals, please refer to the
following:
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemobjectclassreferenceequalstopic.asp
If anything is unclear, please feel free to reply to the post.
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
--------------------
| From: "Bernie Yaeger" <(E-Mail Removed)>
| References: <028f01c3a558$9bfbee70$(E-Mail Removed)>
| Subject: Re: DataRow Index
| Date: Sat, 8 Nov 2003 23:48:44 -0500
| Lines: 49
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <(E-Mail Removed)>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| NNTP-Posting-Host: ool-18b80c4e.dyn.optonline.net 24.184.12.78
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:65860
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Hi Mauricio,
|
| Develop a dataview of the table and then you will get the index. Here's
how
| it works:
|
| Dim arrayseeks(0) As Object
|
| Dim ifinds As Integer
|
| Dim vues As New DataView(dsshipcode.Tables(0))
|
| vues.Sort = "shipcode"
|
| Dim irow as datarow
|
| For Each irow In dsshipcode.Tables(0).Rows
|
| arrayseeks(0) = "12345"
|
| ifinds = vues.Find(arrayseeks)
|
| If ifinds <> -1 Then ' ie, found it
|
| mdescrip = vues(ifinds)("descrip")
|
| Else
|
| mdescrip = ""
|
| End If
|
| Next
|
| In this code, ifind in the index of the found row. I suspect this is what
| you were after.
| HTH,
| Bernie Yaeger
|
| "Mauricio" <(E-Mail Removed)> wrote in message
| news:028f01c3a558$9bfbee70$(E-Mail Removed)...
| > How can I know the index of a DataRow that belongs to a
| > DataTable ?
| > I have the DataRow and I want your Rows' index.
| >
| > Tanks.
| >
| > Mauricio (Brazil)
|
|
|