How to set "Check" on columns with RepositoryItemCheckEdit

0

I have DataGrid that some columns are CheckBox , I'm using the RepositoryItemCheckEdit method of DevExpress to do this:

However, how do I make a Check ? I know I need to use the gridView1.SetRowCellValue property, but even setting the value to true CheckBox of column remains Uncheck

I have the same problem as this link: RepositoryItemCheckEdit does not stay checked but even so I could not solve it.

Code of RepositoryItemCheckEdit

private void check_column()
    {
        DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit acessar_select = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();

        gridView1.Columns["ACESSAR"].ColumnEdit = acessar_select;

        acessar_select.ValueChecked = true;
        acessar_select.ValueUnchecked = false;
        acessar_select.AllowGrayed = false;
        acessar_select.CheckStyle = CheckStyles.Standard;
        acessar_select.NullStyle = DevExpress.XtraEditors.Controls.StyleIndeterminate.Unchecked;

        DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit inserir_select = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();

        gridView1.Columns["INSERIR"].ColumnEdit = inserir_select;

        inserir_select.ValueChecked = true;
        inserir_select.ValueUnchecked = false;
        inserir_select.AllowGrayed = false;
        inserir_select.CheckStyle = CheckStyles.Standard;
        inserir_select.NullStyle = DevExpress.XtraEditors.Controls.StyleIndeterminate.Unchecked;

        DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit editar_select = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();

        gridView1.Columns["EDITAR"].ColumnEdit = editar_select;

        editar_select.ValueChecked = true;
        editar_select.ValueUnchecked = false;
        editar_select.AllowGrayed = false;
        editar_select.CheckStyle = CheckStyles.Standard;
        editar_select.NullStyle = DevExpress.XtraEditors.Controls.StyleIndeterminate.Unchecked;

        DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit excluir_select = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();

        gridView1.Columns["EXCLUIR"].ColumnEdit = excluir_select;

        excluir_select.ValueChecked = true;
        excluir_select.ValueUnchecked = false;
        excluir_select.AllowGrayed = false;
        excluir_select.CheckStyle = CheckStyles.Standard;
        excluir_select.NullStyle = DevExpress.XtraEditors.Controls.StyleIndeterminate.Unchecked;

        DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit imprimir_select = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();

        gridView1.Columns["IMPRIMIR"].ColumnEdit = imprimir_select;

        imprimir_select.ValueChecked = true;
        imprimir_select.ValueUnchecked = false;
        imprimir_select.AllowGrayed = false;
        imprimir_select.CheckStyle = CheckStyles.Standard;
        imprimir_select.NullStyle = DevExpress.XtraEditors.Controls.StyleIndeterminate.Unchecked;
    }    

Code that fills in the data (query the bank):

private void preenche_form(string iduser)
    {
        Classes.Datatable.Datatable_permissoes dat_permis = new Classes.Datatable.Datatable_permissoes();

        DataTable retorno = dat_permis.preenche_permis(iduser);

        DataTableReader dtr = retorno.CreateDataReader();

        if (dtr.HasRows)
        {
            while (dtr.Read())
            {
                string tela = dtr["roleid"].ToString();
                string[] Linha = tela.Split('.');

                string expression = ("id = " + "'" + Linha[0] + "'").ToString();

                DataRow[] index = ret_permi.Select(expression);

                int t = ret_permi.Rows.IndexOf(index[0]);

                if(Linha[1] == "1")
                {

                    gridView1.SetRowCellValue(t, gridView1.Columns["ACESSAR"], true);
                }
                else if (Linha[1] == "2")
                {
                    gridView1.SetRowCellValue(t, gridView1.Columns["INSERIR"], true);
                }
                else if (Linha[1] == "3")
                {
                    gridView1.SetRowCellValue(t, gridView1.Columns["EDITAR"], true);
                }
                else if (Linha[1] == "4")
                {
                    gridView1.SetRowCellValue(t, gridView1.Columns["EXCLUIR"], true);
                }
                else if (Linha[1] == "5")
                {
                    gridView1.SetRowCellValue(t, gridView1.Columns["IMPRIMIR"], true);
                }
            }
        }

Screen:

EDITIONS

Afterresearchingontheinternet,IwasabletodoCheck,butwhenIclickedonacell,itCheckinalloftheline:

    
asked by anonymous 01.11.2016 / 15:16

1 answer

0

Well, after a lot of fighting and spending the day behind an answer, I managed to do it.

The secret is that for every column, you will need a Dictionary (obs. I used Dictionary but can be List and similar).

So I created a checkedMap dictionary for the ACESSAR column and a check_inserir for the INSERIR column

And I set the event below in:

this.gridView1.CustomUnboundColumnData += new DevExpress.XtraGrid.Views.Base.CustomColumnDataEventHandler(this.gridView1_ACESSAR);

Then:

 readonly Dictionary<object, bool> checkedMap = new Dictionary<object, bool>();
    readonly Dictionary<object, bool> check_inserir = new Dictionary<object, bool>();

    private void gridView1_ACESSAR(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
    {
        if (e.IsGetData && e.Column.FieldName == "ACESSAR")
        {
            bool check;

            if (checkedMap.TryGetValue(e.Row, out check))
            {
                e.Value = check;
            }
        }
        else if (e.IsGetData && e.Column.FieldName == "INSERIR")
        {
            bool check;

            if (check_inserir.TryGetValue(e.Row, out check))
            {
                e.Value = check;
            }
        }


        if (e.IsSetData && e.Column.FieldName == "ACESSAR")
        {
            var check = Convert.ToBoolean(e.Value);

            if (checkedMap.ContainsKey(e.Row))
            {
                checkedMap.Remove(e.Row);
            }

            checkedMap.Add(e.Row, check);
        }
        else if (e.IsSetData && e.Column.FieldName == "INSERIR")
        {
            var check = Convert.ToBoolean(e.Value);

            if (check_inserir.ContainsKey(e.Row))
            {
                check_inserir.Remove(e.Row);
            }

            check_inserir.Add(e.Row, check);
        }
    }
    
01.11.2016 / 20:31