Solved

Datagridview - always selects first row - how can I stop this

Posted on 2006-11-08
3
480 Views
Last Modified: 2008-02-01

hi there

Whenever I load data into a datagridview the first row is always selected.  In VB6 days on an MSflexgrid there used to be a highlight on focus command where a row only become selected when a user clicked on the row.

How can I emulate this behaviour?

many thanks!!
0
Comment
Question by:DavidGreenfield
  • 2
3 Comments
 
LVL 34

Expert Comment

by:Sancler
ID: 17896826
One way of doing this - I'm not saying it's the only one, but I haven't found a better - is to add a "dummy" column at column index 0.  Set its minimum width as 2 (which is the smallest allowed for a "visible" column) and its actual width as 2 and all its fore and backcolor properties to Control on the System Colors tab.  Then make sure that the DataGridView's SelectionMode is set to CellSelect.

What then happens is that although the top left cell is then "selected" by default, it is so small that the user can hardly see it and, in any event, its color shows no indication of that selection: it just looks like a slightly wider border on the left edge of the grid.

Then, as soon as a "real" cell is clicked, you can reset selection mode to FullRowSelect if that is what you prefer.

Obviously, you will also then need to take account of the extra column in any code which relies on column indexes.

Roger
0
 
LVL 10

Accepted Solution

by:
Kinger247 earned 500 total points
ID: 17896858
Put this in your DataGridView resize event:

        Try
            DataGridView.Rows(DataGridView.CurrentRow.Index).Selected = False
        Catch
        End Try
0
 
LVL 34

Expert Comment

by:Sancler
ID: 17897045
That is a better way ;-)

Although it doesn't work for me in resize, it does once the binding is complete.

Roger
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

19 Experts available now in Live!

Get 1:1 Help Now