Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-11-08
3
Medium Priority
?
490 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
[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
  • 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

610 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