Results 1 to 3 of 3

Thread: New DataGridView Problem.please help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    125

    New DataGridView Problem.please help

    hi all...
    can anybody tell me how can i get the value from selected row from datagridview, and use this value to do another search and assign the results in another datagridview..

    for example, i type keyword in textbox bar, the datagridview will bring out the relevant records, i click each row that present in this datagridview, i want to read each rows the particular field's value, e.g

    assume i got three records in first datagridview(this datagridview gets records from every time user input the keyword to search
    VB Code:
    1. messageNumber      MessageStatus        DeliveryNumber
    2.                  1000                 original               200GB
    3.                  2000                  Original              200GB
    4.                  3000                  Original              200GB
    so when i input 200GB in search bar, the first datagridview result will present at above .. now i click each rows, i want get each rows messagenumber, so the second datagridview will based on messagenumber in order to find out the table's record, so that can be presented in second datagridview.
    so assume i click the first row in first datagridview, the second datagridview new record maybe like
    VB Code:
    1. :       CHReference               Mile                      LorryID            MessageNumber
    2.              101                         56.7                       yu312            1000

    (but i didn't build up the relation between two tables,because i loaded two tables in different method, not all of their records are matched. so there are no relationships in database. but some of fields like messagenumber exists both two tables)

    can you provide your sample code please??
    i am very appriciate your help!
    Last edited by scotish_bagpipe; Aug 17th, 2006 at 03:08 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: New DataGridView Problem.please help

    Each cell has a Value property that returns the value stored in that cell, but if your grid is bound then you should avoid interacting with the grid's data and use the underlying data source. If you've bound to a BindingSource then you get the value from a field by specifying the row index to get a DataRowView object. So, if you want to select all the rows in a grid where the DeliveryNumber column contains "200GB" you'd something lik this:
    VB Code:
    1. Dim row As DataRowView
    2.  
    3. For index As Integer = 0 To myBindingSource.Count - 1 Step 1
    4.     row = DirectCast(myBindingSource(i), DataRowView)
    5.  
    6.     If CStr(row("DeliveryNumber")) = "200GB" Then
    7.         myDataGridView.Rows(i).Selected = True
    8.     Else
    9.         myDataGridView.Rows(i).Selected = False
    10.     End If
    11. Next index
    or, more succinctly:
    VB Code:
    1. For Each row As DataGridViewRow In myDataGridView.Rows
    2.     row.Selected = (DirectCast(row.DataBoundItem, DataRowView)("DeliveryNumber").ToString() = "200GB")
    3. Next row
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    125

    Re: New DataGridView Problem.please help

    sorry, maybe you misunderstand what i mean is how to according datagridview1 record's messagenumber to find out the datagridview2's record that the messagenumber match with the first one. the first datagridview records are based on user type the keyword to secarch out. the second datagridview' records are based on when i click the each row's result from first datagridview. so in my sample data, when i click one of row in datagridview, the corresponding record will display on the second datagridview., they matched with messagenumber, but they are no relationships in database..
    thank you for your kind help!dude

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width