0
votes

I paste formatted text array to data grid and it works fine. However, when the datagrid is editing mode I want to paste the clipboard data exactly where the cursor point is. By default datagrid's can paste any point of selection.

Is it possible to get the SelectionIndex of DataGridTextColumn when its in editing Mode(Not SelectedIndex) in WPF?

DataGridCellInfo cell1 = data_grid.SelectedCells[datagridColumn];
string text = Convert.ToString((cell1.Item as ChoiceList).Choice);
TextBox textBox = new TextBox();
textBox.Text = text+ data[0,0];
int ind = ((cell1.Item as ChoiceList).Id) - 1;
ChoiceListView[ind].Choice = textBox.Text;
1
I'm not sure I understand the question. Do you want the index of the caret inside the TextBox of the DataGridTextColumn? (e.g. "Hello W|orld" caret is at position 7)Keith Stein
I want the index of the caret inside the TextBox of the DataGridTextColumn such as "Hello W|orld" caret is at position 7sudeesh mohan
Did my solution work?Keith Stein

1 Answers

0
votes

I'm still not sure I fully understand, but I think you're looking for something like this:

//Assuming datagridColumn is the index of the column you want

ChoiceList item = (ChoiceList)data_grid.SelectedItem;
if (item != null)
{
    DataGridRow row = (DataGridRow)dg.ItemContainerGenerator.ContainerFromItem(item);
    TextBox tb = (TextBox)data_grid.Columns[datagridColumn].GetCellContent(row);
    tb.SelectedText = (string)data[0, 0];
}