Hi solardog,
Before we go any further, could you please answer the questions below:
1. Which DataGrid do you refer to, DataGrid or DataGridView?
2. What is the state of the cell when you want to get the strings, in editing or not?
As far as I know, we can achieve your goal in a DataGridView. We can get the inner TextBox in the
EditingControlShowing event handler. Then we can call the
GetCharIndexFromPosition method to get the index at the mouse position. This is a code snippet:
public class CustomDataGridView : DataGridView
{
private TextBox _textBox = null;
protected override void OnEditingControlShowing(DataGridViewEditingControlShowingEventArgs e)
{
base.OnEditingControlShowing(e);
//Get the TextBox instance.
if (e.Control is TextBox)
_textBox = e.Control as TextBox;
}
//Get the split strings: string1, string2
public void SplitString(out string string1, out string string2)
{
if (_textBox != null)
{
//Get the index of the char in the mouse position
int index = _textBox.GetCharIndexFromPosition(_textBox.PointToClient(Control.MousePosition));
string1 = _textBox.Text.Substring(0, index);
string2 = _textBox.Text.Substring(index);
}
else
{
string1 = ""; string2 = "";
}
}
}
Let me know if this helps or not.
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.