Setting multiple columns to read-only wxGrid Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
mazeem3
Earned a small fee
Earned a small fee
Posts: 17
Joined: Fri Jul 14, 2017 6:12 pm

Setting multiple columns to read-only wxGrid

Post by mazeem3 »

I am trying to set multiple columns in my wxGrid as read-only

Code: Select all

    
    wxGridCellAttr *attrRO = new wxGridCellAttr;
    attrRO->SetReadOnly();
    grid->SetColAttr(0, attrRO);
    grid->SetColAttr(2, attrRO);
    grid->SetColAttr(3, attrRO);
    grid->SetColAttr(4, attrRO);
    grid->SetColAttr(5, attrRO);
    grid->SetColAttr(6, attrRO);
    grid->SetColAttr(7, attrRO);
    grid->SetColAttr(8, attrRO);
    grid->SetColAttr(9, attrRO);
    grid->SetColAttr(10, attrRO);
    grid->SetColAttr(11, attrRO);
    grid->SetColAttr(12, attrRO);
    
I want all my columns except column# 1 to be read-only. If i run the code as is i get an error.
But if i only set one column there is no error
Attachments
Capture.PNG
Capture.PNG (27.53 KiB) Viewed 1065 times
mazeem3
Earned a small fee
Earned a small fee
Posts: 17
Joined: Fri Jul 14, 2017 6:12 pm

Re: Setting multiple columns to read-only wxGrid

Post by mazeem3 »

I was able to solve the problem by doing so

Code: Select all

   
    for( int r = 0; r < grid->GetNumberCols() ; r++)
    {
        if (r != 1)
        {
            attrRO = new wxGridCellAttr;
            attrRO->SetReadOnly();
            grid->SetColAttr(r, attrRO);
        }

    }
I think you need to create a new instance of wxGridCellAttr for each column
Post Reply