Solved

Newbie: Quickly select rows based on unique value

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now