473,789 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to make the datagrid view not hightlight the first row?

When you retrieve records to diplay in a DataGridView control the first
record has the background highlighted even though no row is yet selected.
Does anyone know a way to suppress this first record highlighting after
pulling the records into the grid?
Jul 26 '08 #1
5 9107
On Sat, 26 Jul 2008 13:35:44 -0600, "bill" <bi**@bottlegar den.com>
wrote:
>When you retrieve records to diplay in a DataGridView control the first
record has the background highlighted even though no row is yet selected.
Does anyone know a way to suppress this first record highlighting after
pulling the records into the grid?
Your description isn't quite correct. The first row is in fact
selected - if you look at DataGridView.Se lectedRows you should see the
first row in the list.

I don't know of any way to prevent the first row from being selected.
You have to arrange to unselect it after the DataGridView selects it.

If the datagridview is visible at the time you set it's DataSource,
then calling DataGridView.Cl earSelection() immediately after setting
the DataSource will most likely work.

If you are setting the DataSource during the construction of a form
before the Load event fires, then you may have to call ClearSelection
later, perhaps in the Form.Load event.
Jul 26 '08 #2
The problem I see it that the little chevron doesn't show to the left of the
highlighted row. It is highlighted but until that chevron is there if you
try to reference the data set in that row it errors out. I can't seem to
test for it either.

"Jack Jackson" <jj******@cinno vations.netwrot e in message
news:s0******** *************** *********@4ax.c om...
On Sat, 26 Jul 2008 13:35:44 -0600, "bill" <bi**@bottlegar den.com>
wrote:
>>When you retrieve records to diplay in a DataGridView control the first
record has the background highlighted even though no row is yet selected.
Does anyone know a way to suppress this first record highlighting after
pulling the records into the grid?

Your description isn't quite correct. The first row is in fact
selected - if you look at DataGridView.Se lectedRows you should see the
first row in the list.

I don't know of any way to prevent the first row from being selected.
You have to arrange to unselect it after the DataGridView selects it.

If the datagridview is visible at the time you set it's DataSource,
then calling DataGridView.Cl earSelection() immediately after setting
the DataSource will most likely work.

If you are setting the DataSource during the construction of a form
before the Load event fires, then you may have to call ClearSelection
later, perhaps in the Form.Load event.

Jul 27 '08 #3
I am not sure how you "test for it".

The DataGridView has two separate things, selected rows (the
SelectedRows collection) and CurrentRow, the current row. The marker
in the row header (the left-most column) marks the current row. You
can change which row is current by setting the CurrentCell property to
a cell in the row you wish to make current.

I don't understand what you mean by "if you try to reference the data
set in that row it errors out". If you get an error, please always
say what the error is. How are you trying to reference the data?

On Sun, 27 Jul 2008 00:30:40 -0600, "bill" <bi**@bottlegar den.com>
wrote:
>The problem I see it that the little chevron doesn't show to the left of the
highlighted row. It is highlighted but until that chevron is there if you
try to reference the data set in that row it errors out. I can't seem to
test for it either.

"Jack Jackson" <jj******@cinno vations.netwrot e in message
news:s0******* *************** **********@4ax. com...
>On Sat, 26 Jul 2008 13:35:44 -0600, "bill" <bi**@bottlegar den.com>
wrote:
>>>When you retrieve records to diplay in a DataGridView control the first
record has the background highlighted even though no row is yet selected.
Does anyone know a way to suppress this first record highlighting after
pulling the records into the grid?

Your description isn't quite correct. The first row is in fact
selected - if you look at DataGridView.Se lectedRows you should see the
first row in the list.

I don't know of any way to prevent the first row from being selected.
You have to arrange to unselect it after the DataGridView selects it.

If the datagridview is visible at the time you set it's DataSource,
then calling DataGridView.Cl earSelection() immediately after setting
the DataSource will most likely work.

If you are setting the DataSource during the construction of a form
before the Load event fires, then you may have to call ClearSelection
later, perhaps in the Form.Load event.
Jul 27 '08 #4
Before testing try
IsNothing(MyDat aGridView.Curre ntRow)

This should at least stop u from accessing a row that is not valid at the
current moment in time.



"bill" <bi**@bottlegar den.comwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
The problem I see it that the little chevron doesn't show to the left of
the highlighted row. It is highlighted but until that chevron is there if
you try to reference the data set in that row it errors out. I can't seem
to test for it either.

"Jack Jackson" <jj******@cinno vations.netwrot e in message
news:s0******** *************** *********@4ax.c om...
>On Sat, 26 Jul 2008 13:35:44 -0600, "bill" <bi**@bottlegar den.com>
wrote:
>>>When you retrieve records to diplay in a DataGridView control the first
record has the background highlighted even though no row is yet selected.
Does anyone know a way to suppress this first record highlighting after
pulling the records into the grid?

Your description isn't quite correct. The first row is in fact
selected - if you look at DataGridView.Se lectedRows you should see the
first row in the list.

I don't know of any way to prevent the first row from being selected.
You have to arrange to unselect it after the DataGridView selects it.

If the datagridview is visible at the time you set it's DataSource,
then calling DataGridView.Cl earSelection() immediately after setting
the DataSource will most likely work.

If you are setting the DataSource during the construction of a form
before the Load event fires, then you may have to call ClearSelection
later, perhaps in the Form.Load event.


Jul 28 '08 #5
Excellent to know. Thank you!

"Kevin S Gallagher" <ke************ ***@state.or.us wrote in message
news:Ob******** ******@TK2MSFTN GP06.phx.gbl...
Before testing try
IsNothing(MyDat aGridView.Curre ntRow)

This should at least stop u from accessing a row that is not valid at the
current moment in time.



"bill" <bi**@bottlegar den.comwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
>The problem I see it that the little chevron doesn't show to the left of
the highlighted row. It is highlighted but until that chevron is there
if you try to reference the data set in that row it errors out. I can't
seem to test for it either.

"Jack Jackson" <jj******@cinno vations.netwrot e in message
news:s0******* *************** **********@4ax. com...
>>On Sat, 26 Jul 2008 13:35:44 -0600, "bill" <bi**@bottlegar den.com>
wrote:

When you retrieve records to diplay in a DataGridView control the first
record has the background highlighted even though no row is yet
selected.
Does anyone know a way to suppress this first record highlighting after
pulling the records into the grid?
Your description isn't quite correct. The first row is in fact
selected - if you look at DataGridView.Se lectedRows you should see the
first row in the list.

I don't know of any way to prevent the first row from being selected.
You have to arrange to unselect it after the DataGridView selects it.

If the datagridview is visible at the time you set it's DataSource,
then calling DataGridView.Cl earSelection() immediately after setting
the DataSource will most likely work.

If you are setting the DataSource during the construction of a form
before the Load event fires, then you may have to call ClearSelection
later, perhaps in the Form.Load event.



Jul 31 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1316
by: Eddie B. | last post by:
Does anyone know how-to make it so that when my datagrid loads the first row is not selected? I am trying to make a touch screen application and the first row in the grid is selected by default and I do not want any row selected by default? Thanks' Eddie
5
7107
by: ComputerStop | last post by:
I am attempting to print a datagridview. I have not found any method that works successfully. Has any one been successful with this?
2
2295
by: Bob | last post by:
I looked at the sample in the msdn january 2005 - Introducing a new datagrid, but the project downloaded failed to open. Any one can point me to a bit of code on how to go and select an image that will get put in the datagridview. The column is bound to a sql server 2005 image data field. I just need to know how to put the image in the column. Any help appreciated. Bob
0
1207
by: shukyh | last post by:
Hi all I would like to generate an HTML page from datagridview in win application (not webform). In th datagrid view I have DataGridViewCheckBoxColumn columns. How Can i do this? Thanks, Shuky
0
1115
by: Tony A. | last post by:
I'm using VB 2005 with MS Access for as the database. I have a table (tblItem) that has two columns, ItemNum (key field) and ItemDescription. I also have a second table (tblOrdersDetail), this table has two columns ItemNum and ItemDescription Using a Datagrid View that is bound to the tblOrdersDetail table. When a users enters a number in the ItemNum column of the datagrid view I'd like the ItemDescription column of the datagrid view...
1
2593
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
How do I get the value of a checkbox in a row in a datagrid view please? I have tried many methods and nothing workds. This was so much easier in VB 6.0. THanks for any help you can give me.
1
1767
by: radhikabista | last post by:
hey friends , i m not being able to save the updates in datagrid view when i press buttonsave_ gridview i have a class customer with two methods one to get the dataset and other to update database: i dont know what is the problem with my code. i always get UPDATE syntax run time error, as i press button_save_grod view : please help me. my code goes like this: public class customer { // private static string strConn;
1
3833
mafaisal
by: mafaisal | last post by:
Hello Experts I am Using vb.net 2005 Hw To Put DateTime Picker in Datagrid view I have to sea Datetime Picker in Specified Cilomn of Datagrid I try This But The Location Hw To Change to the column location or In DatagridView any Datetime Picker like DataGridViewComboBoxColumn,DataGridViewCheckBoxColumn etc..?
0
1568
by: menyki | last post by:
pls i designed a database application using visual basic. i have done the coding for the print incase i want to print out the data. Pls my problem is how to code at design time for the application to print the data in a tabular form. for now the records prints ontop of each other, i want the records and the field separated by rows and cells of a table as normal. I used Ms access to design the database and the data is displayed by datagrid...
1
1911
by: chandan | last post by:
Hi All! How to Export Datagrid view data to excel in ASP.net 3.5? Thanks, Chandan
0
10404
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.