By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,659 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,659 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
On Sat, 26 Jul 2008 13:35:44 -0600, "bill" <bi**@bottlegarden.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.SelectedRows 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.ClearSelection() 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

P: n/a
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******@cinnovations.netwrote in message
news:s0********************************@4ax.com...
On Sat, 26 Jul 2008 13:35:44 -0600, "bill" <bi**@bottlegarden.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.SelectedRows 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.ClearSelection() 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

P: n/a
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**@bottlegarden.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******@cinnovations.netwrote in message
news:s0********************************@4ax.com.. .
>On Sat, 26 Jul 2008 13:35:44 -0600, "bill" <bi**@bottlegarden.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.SelectedRows 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.ClearSelection() 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

P: n/a
Before testing try
IsNothing(MyDataGridView.CurrentRow)

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



"bill" <bi**@bottlegarden.comwrote in message
news:%2****************@TK2MSFTNGP05.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******@cinnovations.netwrote in message
news:s0********************************@4ax.com...
>On Sat, 26 Jul 2008 13:35:44 -0600, "bill" <bi**@bottlegarden.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.SelectedRows 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.ClearSelection() 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

P: n/a
Excellent to know. Thank you!

"Kevin S Gallagher" <ke***************@state.or.uswrote in message
news:Ob**************@TK2MSFTNGP06.phx.gbl...
Before testing try
IsNothing(MyDataGridView.CurrentRow)

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



"bill" <bi**@bottlegarden.comwrote in message
news:%2****************@TK2MSFTNGP05.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******@cinnovations.netwrote in message
news:s0********************************@4ax.com.. .
>>On Sat, 26 Jul 2008 13:35:44 -0600, "bill" <bi**@bottlegarden.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.SelectedRows 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.ClearSelection() 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 discussion thread is closed

Replies have been disabled for this discussion.