Datagrid Issue

S

Sean

Hi,

I have a datagrid that I want to have a row highlighted when the mouse click
on any cell. I am able to accomplish it. But when I use the arrow keys to
move the cursor up/down I don't heve any row highlighted. Basically I want
to know what event is triggered when I move the up/down arrow keys so I can
highltght record.

Thanks for any help.
Sean
 
C

ClayB [Syncfusion]

You can watch the PositionChanged event on the currencymanager and select
the row when this changes. Here is some code.

//in Form.Load
BindingManagerBase bmb = this.dataGrid1.BindingContext[dataGrid1.DataSource,
dataGrid1.DataMember];
bmb.PositionChanged += new EventHandler(bmb_PositionChanged);
bmb.Position = 1; //change original position so it will get initially
selected
bmb.Position = 0;


//the handler
private int oldPosition = -1;
private void bmb_PositionChanged(object sender, EventArgs e)
{
BindingManagerBase bmb = sender as BindingManagerBase;
if(oldPosition > -1)
this.dataGrid1.UnSelect(oldPosition);
oldPosition = bmb.Position;
this.dataGrid1.Select(oldPosition);
}

=================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
S

Sean

Thanks Clay. Do you happen to have a VB.net version of it?

Sean
ClayB said:
You can watch the PositionChanged event on the currencymanager and select
the row when this changes. Here is some code.

//in Form.Load
BindingManagerBase bmb =
this.dataGrid1.BindingContext[dataGrid1.DataSource, dataGrid1.DataMember];
bmb.PositionChanged += new EventHandler(bmb_PositionChanged);
bmb.Position = 1; //change original position so it will get initially
selected
bmb.Position = 0;


//the handler
private int oldPosition = -1;
private void bmb_PositionChanged(object sender, EventArgs e)
{
BindingManagerBase bmb = sender as BindingManagerBase;
if(oldPosition > -1)
this.dataGrid1.UnSelect(oldPosition);
oldPosition = bmb.Position;
this.dataGrid1.Select(oldPosition);
}

=================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

Sean said:
Hi,

I have a datagrid that I want to have a row highlighted when the mouse
click on any cell. I am able to accomplish it. But when I use the arrow
keys to move the cursor up/down I don't heve any row highlighted.
Basically I want to know what event is triggered when I move the up/down
arrow keys so I can highltght record.

Thanks for any help.
Sean
 

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