1

データがいっぱいで、データの行をクリックすると自動的にすべてのデータを取得したいということをDataGridView考慮して、どのイベントを使用しますか。DataGridViewイベントを使用してみましたCellContentClickが、行ではなく列データを選択した場合にのみアクティブになります

private void dtSearch_CellContentClick(object sender, DataGridViewCellEventArgs e)
{

}
4

3 に答える 3

1

私は以下を効果的に使用しました。MouseDownのイベントを処理し、DataGridView行全体が強調表示されるように設定して、選択されていることが明らかになるようにします(もちろん、すでに完全な行が選択されている場合を除く)。

    private void dtSearch_MouseDown(object sender, MouseEventArgs e)
    {
        // Get the cell that was clicked from the location of the mouse pointer

        DataGridView.HitTestInfo htiSelectedCell = dtSearch.HitTest(e.X, e.Y);

        if (e.Button == MouseButtons.Left)
        {
            // Make sure that a cell was clicked, and not the column or row headers
            // or the empty area outside the cells. If it is a cell,
            // then select the entire row, set the current cell (to move the arrow to
            // the current row)

            //if (htiSelectedCell.Type == DataGridViewHitTestType.Cell)
            if (htiSelectedCell.Type == DataGridViewHitTestType.RowHeader)
            {
                // do stuff here
            }
        }
    }
于 2012-11-20T00:36:19.387 に答える
1

RowHeaderMouseClickはどうですか。

于 2012-11-20T00:49:37.557 に答える
1

CellClickイベントを使用して、列をループして必要な行の値を取得してみてください。

        private void Form1_Load(object sender, EventArgs e)
    {
        this.dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick);
    }

    public void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        List<object> values = new List<object>();

        int cols = this.dataGridView1.Columns.Count;

        for (int col = 0; col < cols; col++)
        {               

            values.Add(this.dataGridView1[col, e.RowIndex].Value);
        }
    }
于 2012-11-20T01:25:56.583 に答える