Solved

get row number of dataset.table(tableName).rows.find(findKey)

Posted on 2004-04-06
4
2,343 Views
Last Modified: 2012-05-04
dataset.table(tableName).rows.find(findKey) returns a datarow this is all well and good if you want the actual information in that row however i need the numerical value of that row. is it possible to use find or something similar to return the row number of the found value
0
Comment
Question by:BangorCC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
gregasm earned 500 total points
ID: 10771067
I cannot think of any way to do it easily.

But one way that you can is to enumerate the rows and increment a counter.

public int findRow(string colname, string criteria)
{

     for (int i = 0; i < table.rows.count; i++)
     {
           if (table.rows[i].column[colname] == criteria)
                {
                       return i;
                }
     }
     return -1;
}
0
 
LVL 8

Assisted Solution

by:gregasm
gregasm earned 500 total points
ID: 10771084
another way to do it is to add an autoincrement column to the table.

see here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatacolumnclassautoincrementtopic.asp

and then when you use find(), you can retrieve the associated id of the increment column.
0
 

Author Comment

by:BangorCC
ID: 10783268
Yea thats what i thought... it really doesnt make that much sense not to at least have a separate function for finding a record position.
0
 
LVL 4

Expert Comment

by:RichW
ID: 11004594
I don't really think there is a way to get the current row from a dataset, but you can do this from a control that is bound to the dataset, say, like the Datagrid object, by performing a hitTtest.


Dim myGrid As DataGrid = CType(sender, DataGrid)
Dim myHitInfo As DataGrid.HitTestInfo = myGrid.HitTest(e.X, e.Y)
Dim Row As DataRow
Dim intRow as Integer

intRow = myHitInfo.Row '<==  Current selected row




0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question