delete
delete

Reputation:

How to have the DataGridView do the following

I need it to:

  1. Expand the columns to fill the entire width regardless of length of strings.
  2. Select the entire row on click anywhere on it.

I also need to capture a double click and retrive the value of a column, on the row a user clicked. Does the EventArgs e, have this property?

Upvotes: 0

Views: 880

Answers (2)

Greg Buehler
Greg Buehler

Reputation: 3894

  • Expand the columns to fill the entire width regardless of length of strings:

    You'll need to modify the AutoSizeMode, MinimumWidth, FillWeight, and Resizable properties as described in the MSDN article Column Fill Mode in the Windows Forms DataGridView Control

  • Select the entire row on click anywhere on it:

    For any click event dataGridView1.Rows[e.RowIndex].Selected = true;

  • I also need to capture a double click and retrive the value of a column, on the row a user clicked:

    You can use the CellContentDoubleClick or CellMouseDoubleClick to access e.ColumnIndex

Upvotes: 1

PMC
PMC

Reputation: 4756

I think what you are looking to do is set the Column Fill Mode for the width.

Column Fill Mode in the Windows Forms DataGridView Control

You can handle the double click event using CellMouseDoubleClick

DataGridView.CellMouseDoubleClick Event

DataGridViewCellMouseEventArgs e
row = e.RowIndex
column = e.ColumnIndex

Upvotes: 1

Related Questions