Grid column border colour 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
Peterj
Knows some wx things
Knows some wx things
Posts: 38
Joined: Mon Nov 14, 2005 6:48 pm
Location: Australia

Grid column border colour

Post by Peterj » Sat Mar 03, 2007 10:25 am

Is there any way to change the border colour of a column in a wxGrid?

Currently if a column in the grid is selected, the background colour of the column is changed, however I would rather change the border colour of the column so that I can use the background colour to indicate other properties of cell contents.

Any ideas on how this can be achieved?
Using Win XP, Dev C++ 4.9.9.2 wx-beta 6.9

tan
Moderator
Moderator
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan » Sat Mar 03, 2007 12:08 pm

Hi,
currently wxGrid uses one colour for all grids (borders), but you can create custom class derived from wxGrid and redefine virtual method

Code: Select all

    virtual wxPen GetColGridLinePen(int col);
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10

Peterj
Knows some wx things
Knows some wx things
Posts: 38
Joined: Mon Nov 14, 2005 6:48 pm
Location: Australia

Post by Peterj » Sat Mar 03, 2007 9:07 pm

Thanks for your reply. Can you give me an example please?
Using Win XP, Dev C++ 4.9.9.2 wx-beta 6.9

tan
Moderator
Moderator
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan » Sun Mar 04, 2007 8:31 am

Peterj wrote:Thanks for your reply. Can you give me an example please?
Ok,

Code: Select all

class MyGrid : public wxGrid
{
public:
        MyGrid(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxPanelNameStr)
      : wxGrid(parent, id, pos, size, style, name), m_sel_pen(*wxBLACK_PEN) {}

      void SetColSelPen(const wxPen& pen) { m_sel_pen = pen; }
      wxPen GetColSelPen() const { return m_sel_pen; }

      wxPen GetColGridLinePen(int col)
      {
          wxArrayInt sels = GetSelectedCols();
          if( sels.Index(col) != wxNOT_FOUND )   // Selected col
              return m_sel_pen;
          else                                                   // Not selected, default pen
              return GetDefaultGridLinePen();
      }

private:
      wxPen m_sel_pen;
};

.......

MyGrid* grid = new MyGrid(this, wxID_ANY);
grid->SetColSelPen(wxPen(wxColour(255, 0, 0), 2));  // For example :)
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10

Peterj
Knows some wx things
Knows some wx things
Posts: 38
Joined: Mon Nov 14, 2005 6:48 pm
Location: Australia

Post by Peterj » Sun Mar 04, 2007 7:51 pm

Thanks for your response.

Examples like that sure make learning easier.
Using Win XP, Dev C++ 4.9.9.2 wx-beta 6.9

Post Reply