Disable checkbox checked in listview

Asked

Viewed 601 times

1

I added in my ListView the checkbox his pattern "Listview Checkboxes", when he is checked I need to disable the same so that it can no longer be "check", I tried to make the checkbox be as Enable false, but I couldn’t access it, you’re trying to access the property ItemChecked.

    private void Form1_Load(object sender, EventArgs e)
    {
        ColumnHeader header = new ColumnHeader();
        header.Text = "NOME";
        header.Width = 415;
        header.TextAlign = HorizontalAlignment.Center;
        listView1.View = View.Details;
        listView1.GridLines = true;
        listView1.CheckBoxes = true;
        listView1.Columns.Add(header);


        for (int i = 0; i <= 10; i++ )
        {
            listView1.Items.Add(new ListViewItem(new string[] { "NOME_" + i }));
        }
    }

    private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
    {
        if (e.Item.Checked == true)
        {
            MessageBox.Show("CheckBox Checked");

            //Aqui preciso desabilitar o CheckBox que foi Checked pra que não possa ser mais UnChecked
            //ou desbilitar a row inteira
        }

    }

inserir a descrição da imagem aqui

  • You could put the code of this Listview!?

  • Thank you for answering, I put an example code that I created now, because I do not have the code in hand at the moment and an image of how it would be.

1 answer

0


Use the event ItemCheck which will have the desired effect (i.e., it will be simulated like this, as this object could not change its status if it is already checked), where after setting as checked it cannot be checked. Remembering that there is no Enabled in that component.

private void listView1_ItemCheck(object sender, ItemCheckEventArgs e)
{
      if (e.CurrentValue == CheckState.Checked)
      {
          e.NewValue = CheckState.Checked;
      }
}
  • 1

    Thank you, solved my problem, thank you very much.

Browser other questions tagged

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