Disable selection for Datagridview c# Windows Forms line

Asked

Viewed 505 times

1

Hello, thanks for your attention

I want to know how to disable the possibility of selecting a line from a Datagridview

Meudatagridview.Rows[Line disabled]. enable = false;

I’ve tried the Frozen:

MeuDataGridView.Rows[Linha desabilitada].Frozen = true;

It blocks the DataGridView all, can help me?

1 answer

1


If you have a collection of lines that cannot be selected, then you can do it as follows (assuming the lines 1, 3 and 5 cannot be selected):

List<int> linhas = new List<int>() { 1, 3, 5 };

dataGridView1.SelectionChanged += (s, e) =>
{
    if (linhas.Contains(dataGridView1.CurrentRow.Index))
        dataGridView1.ClearSelection();
};
  • Yes, thanks Helped a lot ?

  • Then I no longer see how I would do, but resort to some more "strange" contour to do it. But anyway it would be another question :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.