在datagrid上创建右键单击复制选项

时间:2013-11-02 21:40:40

标签: c# wpf datagrid

我创建了一个似乎没有出现的上下文菜单条 - 我希望出现“复制”选项,并允许在用户权限时将单元格的内容复制到剪贴板点击一个单元格。

知道为什么会这样吗?

private DataGridViewCell GetStartCell(DataGridView dgView)
{
    //get the smallest row,column index
    if (dgView.SelectedCells.Count == 0)
        return null;

    int rowIndex = dgView.Rows.Count - 1;
    int colIndex = dgView.Columns.Count - 1;

    foreach (DataGridViewCell dgvCell in dgView.SelectedCells)
    {
        if (dgvCell.RowIndex < rowIndex)
            rowIndex = dgvCell.RowIndex;
        if (dgvCell.ColumnIndex < colIndex)
            colIndex = dgvCell.ColumnIndex;
    }

    return dgView[colIndex, rowIndex];
}

private Dictionary<int, Dictionary<int, string>> ClipBoardValues(string clipboardValue)
{
    Dictionary<int, Dictionary<int, string>>
    copyValues = new Dictionary<int, Dictionary<int, string>>();

    String[] lines = clipboardValue.Split('\n');

    for (int i = 0; i <= lines.Length - 1; i++)
    {
        copyValues[i] = new Dictionary<int, string>();
        String[] lineContent = lines[i].Split('\t');

        //if an empty cell value copied, then set the dictionary with an empty string
        //else Set value to dictionary
        if (lineContent.Length == 0)
            copyValues[i][0] = string.Empty;
        else
        {
            for (int j = 0; j <= lineContent.Length - 1; j++)
                copyValues[i][j] = lineContent[j];
        }
    }
    return copyValues;
}

0 个答案:

没有答案