本文介绍了datagridview控件,一个带有右侧动态按钮的文本单元格,该怎么办的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击小按钮时,我想在一个大文本框中的一个文本单元格中显示全文.当然,只有在文本单元格具有焦点或该行具有焦点时才会显示小按钮.

请帮助我继续.

I want to show full text in one text cell in a big textbox when I click the small button. of course, the small button only showed when the text cell has the focus or this row has the focus.

Please help me hwo to proceed. thanks in advance.

推荐答案

// This will show a button in the upper right corner
// of a cell in column 0 if a single cell in that
// column is selected or if a single row is selected
//
// button1 is defined elsewhere on the form
// and is initialized with the correct size and is not visible
//
// The click event handler for button1 can display a text box
// at the cell location or take any other appropriate action.

private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
    const int targetColumn = 0;

    DataGridViewCell cell = null;
    if ((dataGridView1.SelectedCells.Count == 1 &&
        dataGridView1.SelectedCells[0].ColumnIndex == targetColumn) ||
        dataGridView1.SelectedRows.Count == 1)
    {
        cell = dataGridView1.CurrentRow.Cells[targetColumn];
        Rectangle rect = dataGridView1.GetCellDisplayRectangle(cell.ColumnIndex,
            cell.RowIndex, true);
        button1.Parent = dataGridView1;
        button1.Location = new Point(rect.Right - button1.Width, rect.Top);
        button1.Visible = true;
    }
    else
        button1.Visible = false;
}


这篇关于datagridview控件,一个带有右侧动态按钮的文本单元格,该怎么办的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 10:33