Cell and Window Coordinates
This section shows you how to compute the cell coordinate from a given window point.
NOTE >> The CellWindowCoord_CS tutorial, which is located in the Tutorials subdirectory of your Objective Grid for .NET installation directory, shows how to use cell and window coordinates.
1. If needed, in the designer, resize the grid so that no more than 15 rows and columns are visible.
2. Replace the FormLoad() method with the following code:
 
private void LoadForm(object sender, System.EventArgs e) {
// Change the size of the grid.
gridControl1.RowCount = 20;
gridControl1.ColCount = 20;
// Freeze the first two rows and first three columns.
gridControl1.FrozenCols = 3;
gridControl1.FrozenRows = 2;
}
3. Build and run the application.
4. Scroll the rows and columns all the way to the end. With the scrollbars at their maximum positions, the row indices start at 1, 2, and then skip to 11.
Figure 18 – Frozen Rows and Columns
5. Add the following function to Form1.cs:
 
private void recalc() {
uint x1, x2;
uint y1, y2;
for( uint i = 1; i <= gridControl1.RowCount; ++i ) {
for( uint j = 1; j <= gridControl1.ColCount; ++j ) {
x1 = gridControl1.ConvertClientCol( j );
y1 = gridControl1.ConvertClientRow( i );
x2 = gridControl1.ConvertCol( j );
y2 = gridControl1.ConvertRow( i );
gridControl1[i,j].Style.Value = "(" + x1 + "," + y1 + ")=>("
+ x2 + "," + y2 + ")";
}
}
}
 
6. In FormLoad(), add a call to recalc():
 
recalc();
7. Build and run the application.
8. Set the scrollbars to their maximums, and widen the last two columns to show the full cell text.
Figure 19 – Coordinates Displayed
The next step is adding a little bit of user interaction to trigger a recalculation.
1. Add MainMenu to the Toolbox if it is not already there, then drag it from the Toolbox onto the form.
2. In the field labeled “Type here” at the top of the form, enter Recalculate.
3. In the properties form, click the event button and enter recalculate_click as the value for the click property.
4. In the code view of the form, locate and modify the recalculate_click() method:
 
private void recalculate_click(object sender,
System.EventArgs e) {
recalc();
}
This calls the method that recalculates and fills the cells on your command.
5. Build and run the application.
6. Set the scrollbars to their maximums, and then click the Recalculate menu. The cells take on new values, except for those in the frozen region (1,1)…(3,2).
Figure 20 – Grid With Recalculated Coordinates