mercredi 25 mai 2016

Binded DataGridViewCheckBoxCells or Unbinded DataGridViewCheckBoxColumns not working

I have to Class, Employee and Days respectfully.

Within FEmployee lays fUserDays which has a list of Days which can be checked true or false. For example if Employee is "UserA" and Days is "Monday 1st", "Tuesday 2nd".

The Plan is for the programs user to be able to toggle on and off what day they are working on.

public class FEmployee  
    {
        public string id { get; set; }
        public string name { get; set; }
        public string icon { get; set; }
        public string pin { get; set; }
        public List<EmployeeDays> fEmployeeDays;
    }

public class FDays
    {
        public string name { get; set; }
        public string icon { get; set; }
        public string id { get; set; }
        public CheckState EmployeeDaysCheckState { get; set; }
    }

When a Employee is created it checks the list of Days, if there is more than one item in the list it adds it to the fEmployeeMark List in this case as well as adding a column about a DataGridView. This is a example of how it should look. Example of Grid

The data is displayed on a DataGridView which is Binded by a BindingSource.

At first, when adding a Employee and its column it was unbound and if the user clicked the checkbox CellContentClick Event which would set the value as true.

However the program saves the file to XML and when it is reopened I could find No way to check the DataGridViewCheckBoxCell even though SystemEmployeeList[employeeIndex].EmployeesDaysList[employeesDaysIndex].EmployeeDaysCheckState is Checked.

I have also tried binded the Employee Column by setting the DataPropertyName to EmployeeDaysCheckState. However that just leads to it selecting all the Days on that Row.

My latest attempt was to combine the properties I needed in Employee and Days and use a new class EmployeeDays.

public class FCMEmployeeDays
    {
        public string DaysId { get; set; }
        public string DaysName { get; set; }
        public bool EmployeeDaysnabled { get; set; }
        public MyCheckBoxItem EmployeeDaysChkBox { get; set; }
    }

However I dont know where to move on from that as it just binds the data to checking everything again.

It would be very helpful if someone can direct me in the correct method to complete this. I am still a Junior and I often overthink stuff but I've spent hours on the problem and I'm pretty lost.




Aucun commentaire:

Enregistrer un commentaire