How to set "Check" in columns with Repositoryitemcheckedit

Asked

Viewed 188 times

0

I have a DataGrid that some columns are CheckBox, I’m using the method RepositoryItemCheckEdit from Devexpress to do this:

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

I have the same problem as this link: Repositoryitemcheckedit doesn’t Stay checked but I still couldn’t solve.

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 filling the data (refer to the database):

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);
                }
            }
        }

Canvas:

inserir a descrição da imagem aqui

EDITION

After I went online, I was able to do Check, but when you click on a cell, it Check across the line:

inserir a descrição da imagem aqui

1 answer

0


Well, after a lot of fighting and spending the day chasing an answer, I was able to do.

The secret is that for each column, a Dictionary (Obs. I used Dictionary but it may be List and similar).

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

And I set the event below at:

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

So:

 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);
        }
    }

Browser other questions tagged

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