wxGridCellChoiceEditor causes wxGrid scroll bars to appear on the bottom row

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
spflanze
Earned some good credits
Earned some good credits
Posts: 130
Joined: Tue Feb 15, 2011 10:02 pm

wxGridCellChoiceEditor causes wxGrid scroll bars to appear on the bottom row

Post by spflanze »

I have wxGrid object within which I have set wxGridCellChoiceEditor as the editor in a column of cells. This wxGrid object's proportion is set to 0. It is just above another wxGrid object that also has its proportion set to 0.

The wxGrid object is inside at wxStaticBoxSizer with proportion set to 0 and vertical orientation.

When I execute the program and double click a cell that wxGridCellChoiceEditor set for, and is on the bottom most wxGrid row, that wxGrid's the scroll bars appear because the Editor's combo box is a bit larger than the cell. What is the best to allow a bit more room for the wxGrid object so the scroll bars do not appear?

The horizontal scroll bar obscures most of the bottom row.
jgrzybowski
Earned some good credits
Earned some good credits
Posts: 113
Joined: Sat Sep 24, 2011 9:32 pm
Location: Poland

Re: wxGridCellChoiceEditor causes wxGrid scroll bars to appear on the bottom row

Post by jgrzybowski »

When I activate chioice editor I do not have any scrollbar, but first deafault value in this chioice editor has got text shorter then cell width (see picture ChoiceEditorShown.jpg). After selection horizontal scroll bar is shown (see picture ChoiceEditorHiddenAfterSelection.jpg), because choosen value is longer then cell width and wxGrid has got set up automatic cell width adjastment - function AutoSizeColumns(). Regards Jarek
Attachments
ChoiceEditorShown.jpg
ChoiceEditorHiddenAfterSelection.jpg
spflanze
Earned some good credits
Earned some good credits
Posts: 130
Joined: Tue Feb 15, 2011 10:02 pm

Re: wxGridCellChoiceEditor causes wxGrid scroll bars to appear on the bottom row

Post by spflanze »

A project that demonstrates this problem can be downloaded here:
http://www.mediafire.com/file/4vro3b1m1 ... ration.zip

The problem becomes apparent when the cell at C2 is double clicked. All its choices have text strings much shorter than cell width.

I found this problem does not exist if there are three or more rows. But the wxGrid object I have this problem with needs only two rows.

I have a second question regarding this project. I find it is necessary to call the wxGridCellChoiceEditor::IncRef() after a wxGridCellChoiceEditor type object is passed to wxGrid::SetCellEditor() or the program crashes on closure. But I find there is no crash if there is one less call to wxGridCellChoiceEditor::IncRef() than the number of times it is passed to a wxGrid::SetCellEditor() type object it also will not crash. This raises the question whether wxGridCellChoiceEditor::IncRef() should be called after the first time it is passed to wxGrid::SetCellEditor(). Should it? See line 122, and the comments above this line, in file Scroll_Bar_Choice_DeomonstrationMain.cpp for an example of this. Should line 122 be removed?
Last edited by spflanze on Thu Oct 19, 2017 4:46 am, edited 1 time in total.
spflanze
Earned some good credits
Earned some good credits
Posts: 130
Joined: Tue Feb 15, 2011 10:02 pm

Re: wxGridCellChoiceEditor causes wxGrid scroll bars to appear on the bottom row

Post by spflanze »

Setting the AutoSizeColumn() true for the columns of interested worked to eliminate the horizontal slider. Thanks :D
jgrzybowski
Earned some good credits
Earned some good credits
Posts: 113
Joined: Sat Sep 24, 2011 9:32 pm
Location: Poland

Re: wxGridCellChoiceEditor causes wxGrid scroll bars to appear on the bottom row

Post by jgrzybowski »

I do not use wxGridCellChoiceEditor::IncRef(). In my functions it looks as following

Code: Select all

void Serial_Com_PLCFrm::PrepareGridControl()
{
    //title
    gridInfo->SetColLabelValue(0, wxT("Parameter"));
    gridInfo->SetColLabelValue(1, wxT("Value"));
    //first row
    gridInfo->SetRowLabelValue(current_row_number, wxT("Speed bit/s"));
    gridInfo->SetCellEditor(current_row_number, 0, new wxGridCellChoiceEditor(stringTablicaBaudrate, true)); //stringTablicaBaudrate - array of wxString
    gridInfo->SetCellValue(current_row_number, 0, wxString::Format(wxT("%d"), baudBaudrate)); //baudBaudrate - integer value
    gridInfo->SetCellOverflow(current_row_number, 0, true);
	//....rest of first cells in next rows
	return;
}
spflanze
Earned some good credits
Earned some good credits
Posts: 130
Joined: Tue Feb 15, 2011 10:02 pm

Re: wxGridCellChoiceEditor causes wxGrid scroll bars to appear on the bottom row

Post by spflanze »

Then each cell must have its own dynamically instantiated cell editor instance, even if many of the cells are to use the same editor?

Is stringTablicaBaudrate dynamically or statically allocated?
jgrzybowski
Earned some good credits
Earned some good credits
Posts: 113
Joined: Sat Sep 24, 2011 9:32 pm
Location: Poland

Re: wxGridCellChoiceEditor causes wxGrid scroll bars to appear on the bottom row

Post by jgrzybowski »

I have never tested one object wxGridCellChoiceEditor for all cells, seems to be possible.
In this example it is follwoing object:

Code: Select all

wxArrayString stringTablicaBaudrate;
//...
stringTablicaBaudrate.Add(wxT("150"));
stringTablicaBaudrate.Add(wxT("300"));       
stringTablicaBaudrate.Add(wxT("600"));
//...
stringTablicaBaudrate.Add(wxT("921600"));
Documents shows two types of constructor
wxGridCellChoiceEditor (size_t count=0, const wxString choices[]=NULL, bool allowOthers=false)
wxGridCellChoiceEditor (const wxArrayString &choices, bool allowOthers=false)
spflanze
Earned some good credits
Earned some good credits
Posts: 130
Joined: Tue Feb 15, 2011 10:02 pm

Re: wxGridCellChoiceEditor causes wxGrid scroll bars to appear on the bottom row

Post by spflanze »

I have unwanted scroll bars appearing again. They appear when I click on the bottom row of a column I have a wxGridCellChoiceEditor type object attached. I do not even have to click on the down point arrowhead. Just click on a cell I have executed the AutoSizeRows() function for the grid.

In wxGrid objects that have two or more rows I can make the scroll bars disappear by clicking on at row above the bottom most one. But I also have a single row one, and no way for the user to make the scroll bars disappear after they appear.

How can I prevent these appearing? How can I make them disappear when they appear?

Under Style I do not have the check boxes checked at wxHSCROLL, wxVSCROLL, and wxALWAYS_SHOW_SB.
Matthias1
In need of some credit
In need of some credit
Posts: 1
Joined: Sat Mar 14, 2020 7:35 am

Re: wxGridCellChoiceEditor causes wxGrid scroll bars to appear on the bottom row

Post by Matthias1 »

I found the piece of code causing the appearance of the of the scrollbar. It is the SetSize method of the wxGridCellChoiceEditor, which calculates a little bit more space than the actual cell size. Just override it like this:

Code: Select all

//! Customized ChoiceCellEditor, which prevents scrollbars
class wxEGridCellChoiceEditor : public wxGridCellChoiceEditor
{

public:
	wxEGridCellChoiceEditor(size_t count = 0, const wxString choices[] = NULL, bool allowOthers = false) : wxGridCellChoiceEditor(count, choices, allowOthers)
	{
	}

	virtual void SetSize(const wxRect& rect) wxOVERRIDE
	{
		wxASSERT_MSG(m_control,
			wxT("The wxGridCellChoiceEditor must be created first!"));

		// Check that the height is not too small to fit the combobox.
		/*
		wxRect rectTallEnough = rect;
		const wxSize bestSize = m_control->GetBestSize();
		const wxCoord diffY = bestSize.GetHeight() - rectTallEnough.GetHeight();
		if (diffY > 0)
		{
			// Do make it tall enough.
			rectTallEnough.height += diffY;

			// Also centre the effective rectangle vertically with respect to the
			// original one.
			rectTallEnough.y -= diffY / 2;
		}
		*/
		//else: The rectangle provided is already tall enough.

		wxGridCellEditor::SetSize(rect);

	}

};

Post Reply