Im developing a calendar control using sourcegrid.
Code snippet:
grid1[tmp, day.DayOfWeek] = new Cells.Cell(day.Day);
grid1[tmp, day.DayOfWeek].View = GridStyler.DefaultCell;
Cells.Cell c = grid1[tmp, day.DayOfWeek] as Cells.Cell;
//c.AddController(GridStyler.SelectController);
string s = CalendarController.Today.ToLongDateString();
s = s.Replace("den", "");
s = s.Trim();
if (s.Equals(day.DateAsString))
{
c.Select = true;
}
Now to my question.
I'm testing the output in the eventhandler grid1_OnCellGotFocus() with a MessageBox telling me the old position and the new position.
The above code is run initially and doesn't involve any user input. I want the eventhandler to run when c.Select=true but it doesn't.
If I click in another cell after the initialization the eventhandler is run twice and I get two outputs the first one says: "Oldposition: -1;-1 New Position: 5;6" The second time the eventhandler runs it tells me "Old position: 5;6 New Position: 5;4". This only happens after initialization. If anyone could help me clear these things out I would be very grateful.
Thanx in advance
Fredrik
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Consider also that you can't change the focus of a cell inside the Form Load event of the form (or when the form it is not totally loaded).
If you need to set the focus in this case I suggest to use the first Form Activate event.
Davide
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Im developing a calendar control using sourcegrid.
Code snippet:
grid1[tmp, day.DayOfWeek] = new Cells.Cell(day.Day);
grid1[tmp, day.DayOfWeek].View = GridStyler.DefaultCell;
Cells.Cell c = grid1[tmp, day.DayOfWeek] as Cells.Cell;
//c.AddController(GridStyler.SelectController);
string s = CalendarController.Today.ToLongDateString();
s = s.Replace("den", "");
s = s.Trim();
if (s.Equals(day.DateAsString))
{
c.Select = true;
}
Now to my question.
I'm testing the output in the eventhandler grid1_OnCellGotFocus() with a MessageBox telling me the old position and the new position.
The above code is run initially and doesn't involve any user input. I want the eventhandler to run when c.Select=true but it doesn't.
If I click in another cell after the initialization the eventhandler is run twice and I get two outputs the first one says: "Oldposition: -1;-1 New Position: 5;6" The second time the eventhandler runs it tells me "Old position: 5;6 New Position: 5;4". This only happens after initialization. If anyone could help me clear these things out I would be very grateful.
Thanx in advance
Fredrik
Hi,
First consider that in SourceGrid there is a difference between focus and selection.
See this link for more info:
http://www.devage.com/SourceGrid/SourceGrid_EN.html#FocusAndSelection
Basically to change the focus you must use :
Grid.Selection.Focus(Position pos)
When you have Position -1,-1 it is considered an empty position (yoy can test it with the Position.Empty).
Davide
Consider also that you can't change the focus of a cell inside the Form Load event of the form (or when the form it is not totally loaded).
If you need to set the focus in this case I suggest to use the first Form Activate event.
Davide