How, when user click on a text cell of a datagridview, the editable area of the cell became bigger than the cell(span 3 rows and 2 columns), which make it easier for the user to edit
Thanks
How, when user click on a text cell of a datagridview, the editable area of the cell became bigger than the cell(span 3 rows and 2 columns), which make it easier for the user to edit
Thanks
Change editable area of datagridview
Kauli123
You can change the rowheight but not the width
private void dataGridView1_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
{
dataGridView1.Rows[e.Row.Index].Height = dataGridView1.RowTemplate.Height * 3;
}
private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.Rows[e.RowIndex].Height = dataGridView1.RowTemplate.Height;
}
progames25
Hi,
How about doing in the following way Hope it helps.
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control is TextBox)
{
Rectangle rect = this.dataGridView1.GetCellDisplayRectangle(this.dataGridView1.CurrentCell.ColumnIndex, this.dataGridView1.CurrentCell.RowIndex, false);
int curHeight = rect.Height;
this.dataGridView1.CurrentRow.Height = curHeight * 2;
DataGridViewCellStyle style = new DataGridViewCellStyle();
style.Alignment = DataGridViewContentAlignment.TopLeft;
this.dataGridView1.CurrentCell.Style = style ;
TextBox tx = e.Control as TextBox;
tx.Multiline = true;
}
}
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
this.dataGridView1.CurrentRow.Height = this.dataGridView1.RowTemplate.Height;
}
Regards.
Ye
Alastair Q
First of all, why it is done in DefaultValuesNeeded() Does it handle the "Cell Clicked" or "Cell Entered" event
Second, I don't means to change the height of the row. Instead, the size of the editing control inside the cell should be changed.
Thanks a lot!
Ken
Steve Cronk
For resizing of cell width, you can adjust the width of the current column, as:
this.dataGridView1.Columns[e.ColumnIndex].Width = // width you want to set.