DataGridViewRow.Height

  • Thread starter Thread starter Yury
  • Start date Start date
Y

Yury

Hi,

I want to make row higher when it is seleceted. See following code:

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

List<Item> items = new List<Item>();
for (int i = 0; i < 100; i++)
{
items.Add(new Item());
}

itemDataGridView.SelectionMode =
DataGridViewSelectionMode.FullRowSelect;
itemBindingSource.DataSource = items;
this.itemDataGridView.SelectionChanged += new
EventHandler(itemDataGridView_SelectionChanged);
}

// this method calls one time during form loading, but all rows
have Height = 50
void itemDataGridView_SelectionChanged(object sender, EventArgs
e)
{
if (itemDataGridView.SelectedRows.Count == 1)
{
itemDataGridView.SelectedRows[0].Height = 50;
}
}
}

But after form is loaded ALL ROWS have height = 50. Handler
itemDataGridView_SelectionChanged called only one time during loading.
So what I'm doing wrong?
 
Hi Yury,

Basically, in the class constructor, you are binding and attaching an
event handler, right?
'Handler
itemDataGridView_SelectionChanged called only one time during loading.
' > How is selection_Changed raised when loading? It is supposed to be
called only when the selected index changes. Are you modifying the
selected index in Form_Load or somewhere else?

Also, I think you should add code in itemDataGridView_SelectionChanged
to reset the height of the previously selected row. Otherwise, once you
have selected a row, it's height will remain 50.

Regards,

Jim
 

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

Back
Top