Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Newbie: Quickly select rows based on unique value

Posted on 2004-09-03
5
Medium Priority
?
231 Views
Last Modified: 2012-06-27
I have a grid with many columns. One column, however, has unique values. Is there any way of programmatically selecting the row corresponding to a value of 10, for example, without checking the contents of every cell in the column?  The grid is unbound.
0
Comment
Question by:rdavis101
  • 3
  • 2
5 Comments
 

Author Comment

by:rdavis101
ID: 11978585
Maybe use MyTable.PrimaryKey.IndexOf   ... but how?
0
 
LVL 4

Expert Comment

by:Javert93
ID: 11981331
If you only want to show that one record, you can use a DataView to filter the results based on a column value.
0
 

Author Comment

by:rdavis101
ID: 11981353
Actually what I'd like to do is update that one record...but if I have a table with 1000 records, and if it's the last row in the table, I'd rather not waste time by writing a routine to fine the record myself. I was hoping there was some "built in" way of doing it. With the Janus Grid, for example, there's a Find function that takes a value and a column as arguments.
0
 
LVL 4

Accepted Solution

by:
Javert93 earned 200 total points
ID: 11981551
You can do that with the DataView:

    Private Sub UpdateRecord(ByVal dt As DataTable, ByVal id As Integer, ByVal ParamArray updateValsGoHere() As Object)
        Dim dv As New DataView(dt)

        dv.Sort = "pk_column_name"
        Dim rowIndex As Integer = dv.Find(id)
        If rowIndex < 0 Or rowIndex >= dt.Rows.Count Then
            ' The record wasn't found
        Else
            Dim dataRow As DataRow = dt.Rows(rowIndex)
            ' Do your update here using "dataRow", and be
            ' sure to call Update() on the data adapter
            ' to propogate the changes back to the database
        End If
    End Sub
0
 

Author Comment

by:rdavis101
ID: 11981571
Thanks dude.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Loops Section Overview
Suggested Courses

885 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