Question

I'm new with c#.
I have a GridView + BindingSource.
I fill my binding source with list of items like this:

        public class ListItem
    {
        public DbObject EntityObject { get; set; }
        public bool Used
        {
            get
            {
                return EntityObject != null;
            }
        }

        public int Id
        {
            get
            {
                return EntityObject == null ? 0 : EntityObject.Id;
            }
        }

        public string Name{
            get
            {
               return EntityObject == null ? "<no name>" : EntityObject.ToString(); 
            } 
        }
    }

Data shows in Grid as fine. But i can't check or uncheck checkboxes in Grid. When i not fill field Used:

        public bool Used
        {
           get; set;
        }

Grid became editable again. Whats cant be wrong here?

UPDATE

Now my grid is editable but work not correctly.
I have a 4 raws, 2 raws was checked:

1 unchecked
2 unchecked
3 checked
4 checked

Now i uncheck raw 3:

1 unchecked
2 unchecked
3 unchecked
4 checked

Its fine. Now uncheck raw 4:

1 unchecked
2 unchecked
3 checked
4 unchecked

Now check raw 2:

1 unchecked
2 checked
3 checked
4 checked

Why Grid work so strange?

Was it helpful?

Solution

Currently you have read only property, if you add set also you will able to edit

private bool temp;

public bool Used
{
    get { return temp; }
    set { temp= value; }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top