Solved

Vb.net 2008 DataGribview auto select

Posted on 2009-04-12
6
475 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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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