mardi 28 août 2018

Checkbox column not updating when checked, C# wpf

Here is the code:

public partial class UserForm : UserControl
    {

        public UserForm(IList <Element> list)
        {
            InitializeComponent();

            DataTable dt = new DataTable();

            dt.Columns.Add(" ",typeof(bool));
            dt.Columns.Add("Iteration");
            dt.Columns.Add("View name");
            dt.Columns.Add("Type");

            for (int i = 0; i < list.Count; i++)
            {
                DataRow r = dt.NewRow();

                r[1] = i.ToString();
                r[2] = list[i].Name;
                r[3] = "some element type";

                dt.Rows.Add(r);
            }

            MainGrid.ItemsSource = dt.DefaultView;
            MainGrid.MouseLeftButtonUp += new MouseButtonEventHandler(CellClick);
        }

        private void CellClick(object sender, EventArgs e)
        {
            //Do stuff
        }
    }

So the problem that I'm having is that I can't seem to get multiple checkboxes to be checked. As soon as I try to check a second checkbox the previously checked box becomes unchecked.

The mouse button event was a failed attempt to try to get checkedboxes to remain checked but failed.




Aucun commentaire:

Enregistrer un commentaire