Solved

Vb.net 2008 DataGribview auto select

Posted on 2009-04-12
6
472 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 62

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

12 Experts available now in Live!

Get 1:1 Help Now