Solved

Vb.net 2008 DataGribview auto select

Posted on 2009-04-12
6
479 Views
Last Modified: 2013-11-26
how to make Datagridview auto select when there is only 1 row of data.
0
Comment
Question by:aarontham
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 24125770
Hi aarontham;

The DataGridView should automatically select the first row by default. This is how it can be done
programmatically:

        If DataGridView1.Rows.Count = 1 Then
            DataGridView1.CurrentCell = DataGridView1.Item(0, 0)
        End If

Fernando
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24125773
0
 

Author Comment

by:aarontham
ID: 24128092
hi Guys

sorry for miss understand.
user will enter something on the search TextBox. it will query Database and display result on the datagridview. user will click on the datagridview. i use datagridview MouseClick event to fire. and it will display result into few label.

how can i programmatically automate it when the search result only have 1 row in datagridbiew and it will auto display result into few label.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24135846
If there is only 1 row in the search result, you can call the label population method manually. Put the code that sets the labels into a Sub, then use that sub in the selection change event. After performing search, if there is only one row then call that sub automatically.
0
 

Author Comment

by:aarontham
ID: 24137758
Hi CodeCruiser,

can you help to provide some sample vb.net code?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 24145951
Hi,
You would use something like the following code

Grid_SelectionChangedEvent:
LoadLabels()

btnSearch_Click:
'code for performing search
...
if grid.rows.count = 1 then
   LoadLabels()
end if

Private Sub LoadLabels()
    If grid.selectedrows.count = 1 then
       lblName.text = grid.selectedrows(0).Cells("Name")
       lblAddress.text = grid.selectedrows(0).Cells("Address")
    end if
End Sub
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

728 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