How can I change the Height and Width of the datagridview when clicking on a button.
private void btnResize_Click(object sender, EventArgs e)
{
//code here
}
使用dataGrid.Size = new Size(100,200);
private void btnResize_Click(object sender, EventArgs e)
{
dataGridView1.Height = //set an int desired height;
dataGridView1.Width = //set an int desired Width;
}
Well this is not the smarter way. The better way if it is WPF the use blend behaviour , ChangePropertyAction
and use Button Click as trigger. You can add more than one ChangeProeprtyAction
if you want to set more than one property.
WPF example
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click" SourceObject="{Binding ElementName=button}">
<ei:ChangePropertyAction PropertyName="Height" Value="20"/>
</i:EventTrigger>
</i:Interaction.Triggers>
DataTrigger if you want to change it based on some property value otherwise you can change it to
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.