Custom styles on DataGridView

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I want to apply custom styles on differents rows or columns.
On the DataGrid control there was the TableStyles collection, I haven't see
any equivalent feature...
For example, I want to change rows' height in function of a value (int)
given by user.
The RowTemplate is used only when rows are added. I cannot change existing
rows by changing the row template...
This code works, it change all rows height automaticaly, but it needs to
iterate on each rows...
foreach (DataGridViewRow r in this.dataGridView1.Rows)
{
r.Height = value;
}
before, with the DataGrid, I was using something like that :
myDataGrid.TableStyles(0).PreferredRowHeight = value

I want also change column styles without iterating, just by attribuate a
style to a column...
There is a lot of other things I want to do with styles.

Thank you for helping me :o)
 
Hello,

Sorry, I have made a mistake : I know how to change a column size, I just
want to know to change rows' height in function of a value (int)
given by user.
The RowTemplate is used only when rows are added. I cannot change existing
rows by changing the row template...
This code works, it change all rows height automaticaly, but it needs to
iterate on each rows...
foreach (DataGridViewRow r in this.dataGridView1.Rows)
{
r.Height = value;
}
I have also tried to change this propertie for RowTemplate and refreshed the
DataGridView but it still didn't work.
before, with the DataGrid, I was using something like that :
myDataGrid.TableStyles(0).PreferredRowHeight = value

I want also apply some properties like the column's SortMode to the
DataGridView (all columns).

Thank you for helping me :o)
 
int rowHeight = 20;

private void dataGridView_RowHeightChanged(object sender, DataGridViewRowEventArgs e)
{

rowHeight = e.Row.Height;

this.dataGridView.Invalidate();



}

private void dataGridView_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)

{

DataGridViewRow r = this.dataGridView.Rows[e.RowIndex];

r.Height = rowHeight;

}

 
Back
Top