データがいっぱいで、データの行をクリックすると自動的にすべてのデータを取得したいということをDataGridView
考慮して、どのイベントを使用しますか。DataGridView
イベントを使用してみましたCellContentClick
が、行ではなく列データを選択した場合にのみアクティブになります
private void dtSearch_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
データがいっぱいで、データの行をクリックすると自動的にすべてのデータを取得したいということをDataGridView
考慮して、どのイベントを使用しますか。DataGridView
イベントを使用してみましたCellContentClick
が、行ではなく列データを選択した場合にのみアクティブになります
private void dtSearch_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
私は以下を効果的に使用しました。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
}
}
}
RowHeaderMouseClickはどうですか。
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);
}
}