How to set read-only line of Gridview made with Devexpress?

Asked

Viewed 779 times

2

I need to put the lines of my GridView as read-only. I mean, I have one GridView which already contains some data, this data cannot be edited, but I can add new lines, and these new lines can be edited.

But I’m using the component XtraGrid Devexpress, version 16.1

private void button4_Click(object sender, EventArgs e) // botao editar
    {
        editar = 1;
        readonly_false();
        gridLookUpEdit1.ReadOnly = true;

        int linhas = gridView5.RowCount;

        for(int i = 0; i <= linhas; i++)
        {
           // codigo para colocar as linhas como readonly = true.               
        }
    }

Does anyone have any idea?

2 answers

2


I managed to solve using the event ShowingEditor of GridView:

First, when the user clicks on the "Edit" button we have:

private void button4_Click(object sender, EventArgs e) // botao editar
    {
        // defino editar = 1, para saber que esta em edição
        editar = 1;
        // método para deixar os textbox editaveis (ReadOnly = false)
        readonly_false();
        gridLookUpEdit1.ReadOnly = true;

        // conto quantas linhas existem no GridView 
        it = gridView5.RowCount;
    }

// metodo ligado ao evento ShowingEditor
private void cell_readonly(object sender, CancelEventArgs e)
    {
        if(gridView5.GetSelectedRows()[0] == -2147483647)
        {
            // ocorre quando clicado para adicionar nova linha
        }
        else if (gridView5.GetSelectedRows()[0] < it)
        {
            // ocorre nas linhas que já existiam.

            // cancelo a edição nas colunas com nomes entre ""
            e.Cancel = gridView5.FocusedColumn.FieldName == "DESCRIÇÃO" || gridView5.FocusedColumn.FieldName == "QUANTIDADE"
                       || gridView5.FocusedColumn.FieldName == "OF ORIGEM";
        }
        else
        {
            // ocorre nas linhas que foram adicionadas
        }
    }

0

For the Devexpress Gridview you can use the Gridview.Customrowcelledit Event:

//...
var repositoryItemTextEditReadOnly = new DevExpress.XtraEditors.Repository.RepositoryItemTextEdit();
repositoryItemTextEditReadOnly.Name = "repositoryItemTextEditReadOnly";
repositoryItemTextEditReadOnly.ReadOnly = true;
//...
void gridView1_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e) {
    if(e.RowHandle == 0)
        e.RepositoryItem = repositoryItemTextEditReadOnly;
}

For the . NET.

The estate Readonly indicates whether the data presented by the cell can be edited. You can set Readonly to individual cells, or you can make an entire row or column of read-only cells by setting the Datagridviewrow.Readonly or Datagridviewcolumn.Readonly properties. By default, if a cell or column parent line is set to read-only , the child cells will adopt the same value. You can replace this default behavior by setting Readonly to individual cells. You can navigate to a read-only cell, and you can define a read-only cell to be the current cell. Readonly affects only if a cell is editable ; it does not affect whether the user can delete lines .

In your loop do.

for(int i = 0; i <= linhas; i++)
{
   gridView5.Rows[i].Cells["colName"].ReadOnly = true;             
}
  • This solution would work if I were using the . net components, but I am using the Devexpress components. o GridView Devexpress does not contain the method Rows. Thank you.

  • Good, remove . NET tag

  • Done. Sorry

  • @Thomaserichpimentel, edited .

  • I don’t understand, I need to put in readonly only only the lines that already exist in the GridView, however, more lines can be added, and these have to be editable, ie, ReadOnly = false, I did not understand how this method can help me, I will edit the question, to make it clearer, edited question

Browser other questions tagged

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