You are not logged in.
This forum has been archived and no longer accepts new user registrations. Please report your questions, problems, and feedback to the issue page of ReoGrid on GitHub. Thank you for your cooperation.
I have two modes where the user can manipulate the selection and focus with the arrow keys or cursor.
My goal is to select/highlight a 2x2 range of cells.
Mousing to select a new selection works fine; mousing to a cell highlights/selects (what is precisely the difference?)
a 2x2 region.
I do this with before and after selection range changes property. There is a recursion problem when trying to
change the selection inside a selection changed event.
This works fine. Clicking the mode on button expands the selection to a 2x2
private void UseData_DMT_Mode_checkBox_click ( Object sender , RoutedEventArgs e )
{
Worksheet W = myReoGrid . CurrentWorksheet;
RangePosition RP = W . SelectionRange;
if ( UseData_DMT_Mode_checkBox . IsChecked == true )
{
if ( !RP . IsSingleCell )
return;
CellPosition StartCP = RP . StartPos;
CellPosition EndCP = RP . EndPos;
CellPosition NewEndCP = new CellPosition ( EndCP . Row+1 , EndCP . Col +1);
RangePosition NewRP = new RangePosition ( StartCP , NewEndCP);
W . SelectionMode = WorksheetSelectionMode . Range;
W . BeforeSelectionRangeChange -= W_BeforeSelectionRangeChange;
W . SelectionRange = NewRP;
//W . SelectRange ( Row , Col , 2 , 2 );
W . BeforeSelectionRangeChange += W_BeforeSelectionRangeChange;
W . SelectionStyle = WorksheetSelectionStyle . FocusRect;
}
else
{
W . SelectionStyle = WorksheetSelectionStyle . Default;
}
Debug . WriteLine ( String . Format ( "UseData_DMT_Mode_checkBox_click {0} {1} {2}" , ActionCount, DMTModeClickCount, UseData_DMT_Mode_checkBox . IsChecked ) );
ActionCount++;
DMTModeClickCount++;
}
This does not work with the arrow keys. The selection wanders all over when in DMT mode, for reasons I can
not divine.
I can make a little screen video and post it somewhere so you can see that the hidden arrow key bindings are
interacting with the selection range. The SelectionRange event and the event handler are interacting and
disabling the handler with a -= and restoring it with a += is not working. Moving the selection with the arrow keys is firing a lot of event handlers over and over again; that is why i track the calls and report them.
Here is the code triggered before and after a selection range change:
private void W_BeforeSelectionRangeChange ( Object sender , unvell . ReoGrid . Events . BeforeSelectionChangeEventArgs e )
{
Debug . WriteLine ( String . Format ( "W_BeforeSelectionRangeChange {0} {1}" , ActionCount , BeforeSelectionRangeChangeCount) );
Worksheet W = sender as Worksheet;
if ( UseData_DMT_Mode_checkBox . IsChecked == true )
{
RangePosition RP = W . SelectionRange;
if ( !RP . IsSingleCell )
return;
//CellPosition SS = e . SelectionStart;
//CellPosition SE = e . SelectionEnd;
CellPosition SS = RP . StartPos;
CellPosition NewSE = new CellPosition(RP.EndRow+1, RP.EndCol+1);
RangePosition NewRP = new RangePosition ( SS, NewSE);
W . BeforeSelectionRangeChange -= W_BeforeSelectionRangeChange;
W . BeforeSelectionRangeChange -= W_BeforeSelectionRangeChange;
W . BeforeSelectionRangeChange -= W_BeforeSelectionRangeChange;
W . SelectionMode = WorksheetSelectionMode . Range;
//W . SelectRange ( NewRP);
//W . SelectionRange = NewRP;
W . BeforeSelectionRangeChange += W_BeforeSelectionRangeChange;
W . SelectionStyle = WorksheetSelectionStyle . FocusRect;
Debug . WriteLine ( String . Format ( "{0}=>{1}" , FormattedRange ( W . SelectionRange ) , FormattedRange ( NewRP ) ) );
}
else
{
W . SelectionStyle = WorksheetSelectionStyle . Default;
}
ActionCount++;
BeforeSelectionRangeChangeCount++;
}
and after
private void W_SelectionRangeChanged_EventHandler ( object sender , unvell . ReoGrid . Events . RangeEventArgs e )
{
if ( UseData_DMT_Mode_checkBox . IsChecked == true )
{
Worksheet W = sender as Worksheet;
RangePosition SelRP = W . SelectionRange;
if (!SelRP . IsSingleCell )
return;
CellPosition StartCP = SelRP . StartPos;
CellPosition EndCP = SelRP . EndPos;
CellPosition NewEndCP = new CellPosition ( EndCP . Row + 1 , EndCP . Col + 1 );
RangePosition NewRP = new RangePosition ( StartCP, NewEndCP );
W . SelectionRangeChanged -= W_SelectionRangeChanged_EventHandler;
W . SelectionRangeChanged -= W_SelectionRangeChanged_EventHandler;
W . SelectionRangeChanged -= W_SelectionRangeChanged_EventHandler;
W . SelectionMode = WorksheetSelectionMode . Range;
W . SelectRange ( NewRP );
W . SelectionRangeChanged += W_SelectionRangeChanged_EventHandler;
Debug . WriteLine ( String . Format ( "{0}=>{1}=>{2}" , FormattedRange(e.Range), FormattedRange ( W.SelectionRange ) , FormattedRange ( NewRP ) ) );
}
Debug . WriteLine ( String . Format ( "W_SelectionRangeChanged_EventHandler {0} {1}" ,
SelectionRangeChangedCount , ActionCount ) );
SelectionRangeChangedCount++;
ActionCount++;
}
Specific questions in next post as to the many conflicting Focus, SelectionRange and SelectRange calls.
Offline
What does the meaning of 2x2 selection range? Could you please provide a picture?
Offline
do you have a preferred method for screen casts?
I want to make the minimum selectable region a 2x2 collection of cells.
Offline
Hi
do you have a preferred method for screen casts?
1. Press key "Print Screen" (Prn Scr) on keyboard and Click "Paste" into MS Paint
2. Using http://www.unvell.com/products/justcapture/, http://www.picpick.org/ and other similar software
Last edited by alexeyrlx (2016-06-06 13:07:24)
My English is perfect! (My version of the English language ;-) )
Offline
2x2 selection range can be done by using BeforeSelectionChange event, there is a demo called 'Customize Selection' in the demo project.
Offline
I want to do a demonstration of the phenomena.
I was not certain if the setselectionrange should be set before or after.
The problem only appears with using the arrow keys.
Offline
I am still think that BeforeSelectionChange event can achieve your 2x2 selection range, that event can make sure the selection range always to be a 2 x 2 range, even moved by keyboard. Do you have checked the demo project 'Customize Selection' in demo project? There should be the code you wanted.
Last edited by Jingwood (2016-12-26 07:25:55)
Offline