Solved

Newbie: Quickly select rows based on unique value

Posted on 2004-09-03
5
205 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 50 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

Suggested Solutions

Title # Comments Views Activity
Checking a checkbox based on SQL DataReader boolean value in ASP.NET(VB) 2 45
vb.net 1 month apart 11 38
VB.NET - Refactor Class per SOLID principles 2 33
vb.net sendkey 4 17
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

685 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