Custom styles on DataGridView

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 :blush:)
 
G

Guest

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 :blush:)
 
Joined
Jul 25, 2006
Messages
1
Reaction score
0
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;

}

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top