Rectangle border for the selected row in DataGridView

A

ArunDhaJ

Hi,
I'm using a DataGridView to bind my DataTable. The selection mode is
FullRowSelect. I wanted to show a rectangle border for the
SelectedRow[0]'th items.
I saw in some cases the cell alone is shown with the border, but still
don't know for which setting... :-( I wanted to do the same for the
entire row...


Thanks in Advance
Regards
ArunDhaJ
 
R

Roger

Hi,
First, may I suggest, you just do with out it?
How critical is it after all?

Second, I am not sure it make sense
for the entire Row to have a FocusRect,
since it indicates KeyBoard focus/input,
and the whole row does not get the focus,
only a cell can have focus, right? You
type into a cell not the row.

But, if you still need it, there is always a
Draw event.

Roger
 
V

vanderghast

I would rather use the CellPainting event for that, something like:

if( dataGridView1.CurrentCell.RowIndex == .e.RowIndex)
{
e.AdvancedBorderStyle.Top =
DataGridViewAdvancedCellBorderStyle.OutsetDouble;
e.AdvancedBorderStyle.Bottom=
DataGridViewAdvancedCellBorderStyle.OutsetDouble;
}


and DO NOT SET

e.Handled = true

unless you want also draw the text (or graphics) in each cell.



Vanderghast, Access MVP



Roger said:
Hi,
First, may I suggest, you just do with out it?
How critical is it after all?

Second, I am not sure it make sense
for the entire Row to have a FocusRect,
since it indicates KeyBoard focus/input,
and the whole row does not get the focus,
only a cell can have focus, right? You
type into a cell not the row.

But, if you still need it, there is always a
Draw event.

Roger

ArunDhaJ said:
Hi,
I'm using a DataGridView to bind my DataTable. The selection mode is
FullRowSelect. I wanted to show a rectangle border for the
SelectedRow[0]'th items.
I saw in some cases the cell alone is shown with the border, but still
don't know for which setting... :-( I wanted to do the same for the
entire row...


Thanks in Advance
Regards
ArunDhaJ
 
R

Roger

Hi,
Yes, CellPainting is a good event (there is no
Draw event really; I was loosely speaking).

But, look this event appears
to be useful too: RowPostPaint
it has a parameter of
DataGridViewRowPostPaintEventArgswhich has a DrawFocus member.Looks like
this may be useful.
Roger

vanderghast said:
I would rather use the CellPainting event for that, something like:

if( dataGridView1.CurrentCell.RowIndex == .e.RowIndex)
{
e.AdvancedBorderStyle.Top =
DataGridViewAdvancedCellBorderStyle.OutsetDouble;
e.AdvancedBorderStyle.Bottom=
DataGridViewAdvancedCellBorderStyle.OutsetDouble;
}


and DO NOT SET

e.Handled = true

unless you want also draw the text (or graphics) in each cell.



Vanderghast, Access MVP



Roger said:
Hi,
First, may I suggest, you just do with out it?
How critical is it after all?

Second, I am not sure it make sense
for the entire Row to have a FocusRect,
since it indicates KeyBoard focus/input,
and the whole row does not get the focus,
only a cell can have focus, right? You
type into a cell not the row.

But, if you still need it, there is always a
Draw event.

Roger

ArunDhaJ said:
Hi,
I'm using a DataGridView to bind my DataTable. The selection mode is
FullRowSelect. I wanted to show a rectangle border for the
SelectedRow[0]'th items.
I saw in some cases the cell alone is shown with the border, but still
don't know for which setting... :-( I wanted to do the same for the
entire row...


Thanks in Advance
Regards
ArunDhaJ
 
R

Roger

It later occurred to me there is good need to
draw a focus rectangle around a whole row.
If the DataGridView is MultSelect, the
FocusRect will make it clear which
row is selected/focused.

Roger said:
Hi,
First, may I suggest, you just do with out it?
How critical is it after all?

Second, I am not sure it make sense
for the entire Row to have a FocusRect,
since it indicates KeyBoard focus/input,
and the whole row does not get the focus,
only a cell can have focus, right? You
type into a cell not the row.

But, if you still need it, there is always a
Draw event.

Roger

ArunDhaJ said:
Hi,
I'm using a DataGridView to bind my DataTable. The selection mode is
FullRowSelect. I wanted to show a rectangle border for the
SelectedRow[0]'th items.
I saw in some cases the cell alone is shown with the border, but still
don't know for which setting... :-( I wanted to do the same for the
entire row...


Thanks in Advance
Regards
ArunDhaJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top