【问题标题】:Is it possitble to get SelectionIndex of DataGridTextColumn when its is in editing Mode(Not SelectedIndex) in WPF?当 DataGridTextColumn 在 WPF 中处于编辑模式(非 SelectedIndex)时,是否可以获取其 SelectionIndex?
【发布时间】:2020-05-29 06:03:16
【问题描述】:

我将格式化的文本数组粘贴到数据网格中,它工作正常。但是,当数据网格处于编辑模式时,我想将剪贴板数据准确粘贴到光标所在的位置。默认情况下,数据网格可以粘贴任何选择点。

DataGridTextColumn 在 WPF 中处于编辑模式(Not SelectedIndex) 时,是否可以获取其 SelectionIndex?

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;

【问题讨论】:

  • 我不确定我是否理解这个问题。你想要DataGridTextColumnTextBox 内的插入符号的索引吗? (例如,“Hello W|orld”插入符号位于第 7 位)
  • 我希望 DataGridTextColumn 的 TextBox 中插入符号的索引,例如“Hello W|orld”插入符号位于位置 7
  • 我的解决方案有效吗?

标签: c# .net wpf winforms


【解决方案1】:

我仍然不确定我是否完全理解,但我认为您正在寻找这样的东西:

//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];
}

【讨论】:

    猜你喜欢
    • 2020-12-06
    • 2023-04-10
    • 2011-03-17
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    • 1970-01-01
    • 2019-12-12
    • 1970-01-01
    相关资源
    最近更新 更多