Solved

Newbie: Quickly select rows based on unique value

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 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

14 Experts available now in Live!

Get 1:1 Help Now