We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

GDBG, SelectionChanging and Arrow Keys

Clay, I''m not able to get the correct row index in GDBG when changing the current row with the arrow keys up/down. I''m setting up the ListBoxSelectionMode to One and adding these event handler to the form. I''m modifying the DataBoundSortByDisplayMember to reproduce the behaviour: private void gridDataBoundGrid1_CurrentCellActivating(object sender, Syncfusion.Windows.Forms.Grid.GridCurrentCellActivatingEventArgs e) { if( e.RowIndex > 0 && e.ColIndex > 0 ) { e.ColIndex = 0; } } private void Model_SelectionChanging(object sender, GridSelectionChangingEventArgs e) { if( e.Range.IsRows ) { MessageBox.Show( e.Range.Top.ToString() ); } } When you use the mouse to change the position, the correct index will be in the e.Range. If you use the arrow key up/down, the e.Range.Top still contains the index of the last position. I''m using 2.0.5.1. Regards, Thomas

7 Replies

AD Administrator Syncfusion Team June 17, 2004 07:16 AM

This is likely a bug, but I am not sure whether I am overlooking something that forces things to behave this way in ListBoxSelectionMode. As a work around, I thnk you can handle the grid.KeyDone event (or override OnKeyDown), and raise the event yourself making sure you pass the proper row range. Here is some code that worked for me in a little sample.
private void gridDataBoundGrid1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
	GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
	if(e.KeyCode == Keys.Up && cc.RowIndex > this.gridDataBoundGrid1.Model.Rows.HeaderCount + 1)
	{
		GridRangeInfo currentRange = GridRangeInfo.Row(cc.RowIndex);
		GridRangeInfo newRange = GridRangeInfo.Row(cc.RowIndex - 1);
		GridSelectionChangingEventArgs se = new GridSelectionChangingEventArgs(newRange, GridSelectionReason.ArrowKey, GridRangeInfo.Empty);
		this.gridDataBoundGrid1.Model.RaiseSelectionChanging(se);
		if(!se.Cancel)
		{	
			this.gridDataBoundGrid1.Selections.ChangeSelection(currentRange, newRange, false);
			this.gridDataBoundGrid1.CurrentCell.InternalMove(GridDirectionType.Up, 1, GridSetCurrentCellOptions.None);
		}
		e.Handled = true;
	}
	else if(e.KeyCode == Keys.Down && cc.RowIndex < this.gridDataBoundGrid1.Model.RowCount)
	{
		GridRangeInfo currentRange = GridRangeInfo.Row(cc.RowIndex);
		GridRangeInfo newRange = GridRangeInfo.Row(cc.RowIndex + 1);
		GridSelectionChangingEventArgs se = new GridSelectionChangingEventArgs(newRange, GridSelectionReason.ArrowKey, GridRangeInfo.Empty);
		this.gridDataBoundGrid1.Model.RaiseSelectionChanging(se);
		if(!se.Cancel)
		{	
			this.gridDataBoundGrid1.Selections.ChangeSelection(currentRange, newRange, false);
			this.gridDataBoundGrid1.CurrentCell.InternalMove(GridDirectionType.Down, 1, GridSetCurrentCellOptions.None);
		}
		e.Handled = true;
	}
}


AD Administrator Syncfusion Team June 17, 2004 10:27 AM

Hi Clay Thanks for the code. I''m using the follwing code in SelectionChanging: http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=14870 The row is not going to be current, because of the cancel in SelectionChanging. The move will not be made because se.Cancel is true: this.Model.RaiseSelectionChanging(se); if(!se.Cancel) { this.Selections.ChangeSelection(currentRange, newRange, false); this.CurrentCell.InternalMove(GridDirectionType.Up, 1, GridSetCurrentCellOptions.None); } What I have to change in the code to get it running? Regards, Thomas


AD Administrator Syncfusion Team June 17, 2004 10:40 AM

f.y.i I''m overriding the OnKeyDown method. Regards, Thomas


AD Administrator Syncfusion Team June 17, 2004 03:59 PM

If I understand you properly, you want to not display the current row colored as selected using ListBoxSelectionMode = one. Is this correct? If so, I think you will have to do away with the ListBoxSelectionsMode = one setting. The reason is that with this setting, the current row will always be forced to be selected (Not withstanding anything you do in SelectionsChanging). It would be straight-forward to have a SelectedRow property that was differert than the CurrentCell.RowIndex, and not use ListBoxSelectionMode. In PrepareViewStyleInfo, you could color SelectedRow if it were valid (say > -1). Then you can use CurrentCellMoving to test whether you want to change SelectedRow or not. If I misunderstood what you need, please let me know.


AD Administrator Syncfusion Team June 17, 2004 10:51 PM

Clay, I''ll prepare a sample that exactly shows what I need. Thanks, Thomas


AD Administrator Syncfusion Team June 22, 2004 05:22 AM

Hi Clay, I''m updating the incident 11867 and attaching the sample. Regards Thomas


AD Administrator Syncfusion Team June 22, 2004 07:52 AM

The incident has been updated.

Loader.
Live Chat Icon For mobile
Up arrow icon