Hi,
In our application there is the linking functionality that is very similar to Excel's. A cell may reference other cells (=A1 + B3) as well as other entities of the application, like nodes in the tree (=nodeA). We have the fx bar that is actually the same as Excel's.
The use case under discussion is this: when a user is entering a formula for a cell in the fx bar (again, like in Excel), the formula should be mirrored in the grid's cell as the user types it. Our grid (that is based on Infragistics grid) has the SetActiveCellText method that should do the trick. The implementation of the method is as follows (a little simplified for brevity):
public void SetActiveCellText(string text)
{
ultraGrid.PerformAction(UltraGridAction.EnterEditMode);
ultraGrid.ActiveCell.SelStart = 0;
ultraGrid.ActiveCell.SelLength = text.Length;
ultraGrid.ActiveCell.SelText = text;
}
That works fine except the grid takes the focus during entering edit mode tha actually sounds quite locally.
That was the context for the problem and the question I have is: Is there a way to set grid's active cell selected text without the grid taking focus?
Thanks,
Vitaly
Hi Vitaly,
You cannot access the selected text in the grid without having an ActiveCell. So the grid would have to have focus.
But, you could set the Value of the cell without it having the focus - assuming that the DataType of the column allows strings.
If that's no good, then another option might be to use a DrawFilter. The DrawFilter allows you to override the drawing in the cell so you can draw whatever you like.
Mike,
I didn't like the idea of creating a DrawFilter as it doesn't fit well into our requirements (for example, the user has decided to stop typing formula in the fx bar and want to continue typing it in the cell).
One idea is to have EmbeddableTextBox control created, added to the grid.Controls and put above the needed cell. The fx bar's text box will then work directly with this EmbeddableTextBox control directly and they will be mirroring each other. When the fx bar or this ETB loses focus, the ETB will be immediately removed.
Do you foresee any problem on the surface with this approach?
That seems like a reasonably approach.
But it might be tricky. Suppose the user is typing into the fx bar, so you show your TextBox over the cell and highlight the text. That's fine. But then what happens when the user clicks onto the TextBox?
At that point, you would want the grid cell to go into edit mode and you would want the cursor to appear in the correct place in the cell based on where the user clicked within the TextBox. This would be difficult to accomplish, I think.
thanks for the reasonable point.
That shouldn't be a problem as the user will be allowed to switch between fx bar to 'text box' during entering a formula, like in Excel.
-Vitaly