Solved

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

Posted on 2006-11-08
3
485 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 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

Industry Leaders: 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!

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
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…

690 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