<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.codeblocks.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Grouch</id>
	<title>Code::Blocks - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.codeblocks.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Grouch"/>
	<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php/Special:Contributions/Grouch"/>
	<updated>2026-05-05T14:04:16Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.0</generator>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9275</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9275"/>
		<updated>2017-02-25T02:47:57Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbe2s. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and numbers in some elements of a 20x30 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The code written by wxSmith itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by variables in your program. The code wxSmith writes has the size of the grid given by two constants, the number of rows and the number of columns, but you can easily see from that code how to make the grid's size depend on variables in your code. &lt;br /&gt;
    &lt;br /&gt;
So let's get started. Create a new wxWidgets application. Call it DiaGrid and make it frame-based. We don't want the grid showing all the time, only when we call it up, so we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid for the program.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40 (we will change it later in the code to 20 x 30); '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch. (This was discovered by a lot of trial and error.)&lt;br /&gt;
&lt;br /&gt;
Note that we did not put scroll bars on any of the components we used. The wxGrid component automatically carries its own scroll bars and any others just make for confusion.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of the created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is with the possible exception of the word ''this''. When responding to a button click, ''this'' seems to work; in other contexts the compiler may complain of &amp;quot;illegal use of ''this''&amp;quot; and ''this'' must be replaced by ''NULL''. (If you understand why this is, please explain it.) Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog containing the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label some of the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for now.&lt;br /&gt;
&lt;br /&gt;
Now we can put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line. Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
&lt;br /&gt;
Let's now have a look at the code wxSmith has written for us. To avoid repetition, however, I will show the code after some additions by hand, but with clear markings distinguishing what wxSmith wrote from what was later added. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Barnum::Barnum(wxWindow* parent,wxWindowID id,const wxPoint&amp;amp; pos,const wxSize&amp;amp; size)&lt;br /&gt;
{&lt;br /&gt;
  //(*Initialize(Barnum)&lt;br /&gt;
  wxBoxSizer* BoxSizer2;&lt;br /&gt;
  wxBoxSizer* BoxSizer1;&lt;br /&gt;
  Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE |wxRESIZE_BORDER,  _T(&amp;quot;id&amp;quot;));&lt;br /&gt;
  SetClientSize(wxDefaultSize);&lt;br /&gt;
  Move(wxDefaultPosition);&lt;br /&gt;
  BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);&lt;br /&gt;
  Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T(&amp;quot;ID_PANEL1&amp;quot;));&lt;br /&gt;
  BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);&lt;br /&gt;
  Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(400,300), wxFULL_REPAINT_ON_RESIZE, _T(//*)&lt;br /&gt;
&lt;br /&gt;
//***End of Part 1. Everything above this line was written by wxSmith *******&lt;br /&gt;
&lt;br /&gt;
//                                  Part 2. &lt;br /&gt;
&lt;br /&gt;
// Now comes the hand-coded section (with a few lines borrowed from wxSmith)&lt;br /&gt;
&lt;br /&gt;
    int nrows, ncols;&lt;br /&gt;
    nrows =20; ncols = 30;&lt;br /&gt;
&lt;br /&gt;
    Grid1-&amp;gt;CreateGrid(nrows,ncols); // wxSmith had Grid1-&amp;gt;CreateGrid(40.40);&lt;br /&gt;
    Grid1-&amp;gt;EnableEditing(true);     // from wxSmith&lt;br /&gt;
    Grid1-&amp;gt;EnableGridLines(true);   // from wxSmith&lt;br /&gt;
// Label some columns&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;)); //from wxSmith &lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));  //from wxSmith &lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(2, _(&amp;quot;gamma&amp;quot;)); //from wxSmith &lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(3, _(&amp;quot;delta &amp;quot;));&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(4, _(&amp;quot;epsilon&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Label some rows&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(0, _(&amp;quot;mu&amp;quot;)); // from wxSmith&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(1, _(&amp;quot;nu&amp;quot;)); // from wxSmith&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(2, _(&amp;quot;xi&amp;quot;)); // from wxSmith&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(3, _(&amp;quot;omicron&amp;quot;));&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(4, _(&amp;quot;pi&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Column or row labels can be set from C-strings whose&lt;br /&gt;
// values are determined at runtime by first converting&lt;br /&gt;
// the C-string to a wxString, as illustrated here:&lt;br /&gt;
&lt;br /&gt;
    char colone[10];        //colone is the variable C-string.&lt;br /&gt;
    strcpy(colone,&amp;quot;omega&amp;quot;);// Give it some content at run time.&lt;br /&gt;
    wxString ColumnName;    // Define a wxString which may be used repeatedly.&lt;br /&gt;
// Convert contents of the C-string to a wxString:&lt;br /&gt;
    ColumnName = wxString::FromUTF8(colone);&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0,ColumnName); // Set the label for column 0.&lt;br /&gt;
&lt;br /&gt;
// Set some cell values&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 0, _(&amp;quot;2&amp;quot;)); //from wxSmith&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 1, _(&amp;quot;7&amp;quot;)); //from wxSmith&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 2, _(&amp;quot;6&amp;quot;)); //from wxSmith&lt;br /&gt;
&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Illustrate what SetColFormatFloat() does. From Smart &amp;amp; Hock, page 348 corrected.&lt;br /&gt;
	Grid1-&amp;gt;SetColFormatFloat(5,6,2); // Format numeric strings in column 5.&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0,5,_(&amp;quot;3.14159&amp;quot;)); // Put a number with 5 decimals there.&lt;br /&gt;
    // Put the same string in Column 4 for comparison.&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(0,4,_(&amp;quot;3.14159&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Here is how to show floats defined at run time in the wxGrid:&lt;br /&gt;
    float e = 2.71828;&lt;br /&gt;
    wxString cart;&lt;br /&gt;
    cart = wxString::Format(_T(&amp;quot;%f&amp;quot;), e);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1,4,cart);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1,5,cart);&lt;br /&gt;
&lt;br /&gt;
// Display a matrix of floats defined at run time.&lt;br /&gt;
    short i,j;&lt;br /&gt;
    float xx;&lt;br /&gt;
    for (i = 10; i &amp;lt;=12; i++){&lt;br /&gt;
        for (j = 10; j &amp;lt;= 12; j++){&lt;br /&gt;
            xx = i*j;&lt;br /&gt;
            xx = xx/2.;&lt;br /&gt;
            cart = wxString::Format(_T(&amp;quot;%8.2f&amp;quot;),xx);&lt;br /&gt;
            Grid1-&amp;gt;SetCellValue(i,j,cart);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
//&lt;br /&gt;
//                    *** Part 3 ***&lt;br /&gt;
// All that follows was written by wxSmith.&lt;br /&gt;
	Grid1-&amp;gt;SetDefaultCellFont( Grid1-&amp;gt;GetFont() );&lt;br /&gt;
	Grid1-&amp;gt;SetDefaultCellTextColour( Grid1-&amp;gt;GetForegroundColour() );&lt;br /&gt;
	BoxSizer2-&amp;gt;Add(Grid1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL| wxALIGN_CENTER_VERTICAL, 5);&lt;br /&gt;
	Panel1-&amp;gt;SetSizer(BoxSizer2);&lt;br /&gt;
	BoxSizer2-&amp;gt;Fit(Panel1);&lt;br /&gt;
	BoxSizer2-&amp;gt;SetSizeHints(Panel1);&lt;br /&gt;
	BoxSizer1-&amp;gt;Add(Panel1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);&lt;br /&gt;
	SetSizer(BoxSizer1);&lt;br /&gt;
	BoxSizer1-&amp;gt;Fit(this);&lt;br /&gt;
	BoxSizer1-&amp;gt;SetSizeHints(this);&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
wxSmith has separated its code into three parts – without, however, marking the divisions. I have added the division markers in the above listing. The first part has some preliminaries, the second part creates the grid and puts various values into it, and the third part attends to other matters whose precise function is elusive but presumably very necessary for the program to function properly. &lt;br /&gt;
&lt;br /&gt;
It is Part 2 that the programmer is likely to want to change. The first line of Part2 as written by wxSmith was: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The size of the grid may well not be known at compile time but depend on the matrix to be displayed. Somehow that variable size will be communicated to Barnum, perhaps by parameters in the call, perhaps by global variables, perhaps by a read from a file. To keep matters simple, I have represented that process by just defining nrows and ncols as ints in the code, but as far as the CreateGrid() function knows they came from somewhere else. So our Part2 begins:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    int nrows, ncols;&lt;br /&gt;
    nrows =20; ncols = 30;&lt;br /&gt;
    Grid1-&amp;gt;CreateGrid(nrows,ncols);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Just above these lines we need to mark the end of code that wxSmith controls. That end is marked by a  //*)  sign.  So this mark has been moved to precede these three lines. Part 1 of our code will therefore be everything down to and including this line.  The programmer should have no need to touch it save to allow Barnum to receive some variables from the program that calls it. &lt;br /&gt;
&lt;br /&gt;
We will use the same device for showing how to put floating point numbers known only at run time into the grid. We will define them as floats, and show how to put a float, no matter where it came from, into the grid. &lt;br /&gt;
&lt;br /&gt;
When it comes to displaying floating point numbers in the grid, however, we must deal with what appears to be an error in a couple of lines in the standard and most authoritative book on wxWidgets, ''Cross-Platform GUI Programming with wxWidgets'' by Smart and Hock. In the sole example given of a wxGrid, they write on page 348:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// We can specify that some cells will store numeric&lt;br /&gt;
// values rather than strings. Here we set grid column 5&lt;br /&gt;
// to hold floating point values displayed with width of 6&lt;br /&gt;
// and precision of 2&lt;br /&gt;
grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6, &amp;quot;3.1415&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This passage appears at least 18 times on the Internet without anyone observing that it is totally misleading if not dead wrong. To begin with, the last line is out of date and won't compile, at least not with Code::Blocks. It can be easily updated to:&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
But it does not illustrate the use of the SetColFormatFloat function. That command in the previous line applied to column 5 while this line puts a ''string'' – not a numeric value – into column 6, not 5. We can easily correct the column number:  &lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 5,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
But it is still putting a wxString – not a numeric value, and certainly not a float – into the cell.  It turns out that the assertion that “some cells will store numeric values rather than strings” is highly misleading at best. There is no elementary way to put anything other than a wxString into a cell of a wxGrid, nor to declare that a column will contain floats.  The function of SetColFormatFloat() is quite different. The command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is used to give a ''uniform appearance'' to the column. It makes all strings in column 5 representing numbers with decimal places appear with the same width and precision. Thus, after this command, the string “3.14159” in column 5 will appear as 3.14 and the string “3.1” will appear as 3.10.&lt;br /&gt;
&lt;br /&gt;
So then how do we show a floating point number in a wxGrid? We first have to convert it to a wxString and then put the string into the wxGrid. For example, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    float e = 2.71828; &lt;br /&gt;
    wxString cart; &lt;br /&gt;
    cart = wxString::Format(_T(&amp;quot;%f&amp;quot;), e);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart); &lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 5, cart); // To show what SetColFormatFloat does. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here ''cart'' is the wxString in which the numeric value of ''e'' rides into the grid. &lt;br /&gt;
Column or row labels can be set from C-strings whose values are determined at runtime by first converting the C-string to a wxString, as illustrated here:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    char colone[10];        //colone is the variable C-string.&lt;br /&gt;
    strcpy(colone,&amp;quot;alpha&amp;quot;);// Give it some content at run time.&lt;br /&gt;
    wxString ColumnName;    // Define a wxString which may be used repeatedly.&lt;br /&gt;
	 //Convert contents of the C-string to a wxString:&lt;br /&gt;
    ColumnName = wxString::FromUTF8(colone);&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0,ColumnName); // Set the column label.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When these lines have been added to Barnum and the code compiled and run, we get the result shown below.&lt;br /&gt;
&lt;br /&gt;
[[File : DiaGridFinal.png | |center|]]]&lt;br /&gt;
&lt;br /&gt;
Note that the floating point numbers appear with their full number of decimal places in column 4 (labeled &amp;quot;epsilon&amp;quot;)but in column 5 they have been rounded to 2 decimal places as a result of the SetColFormatFloat()  function.&lt;br /&gt;
&lt;br /&gt;
The last section of Part 2 shows how the wxString ''cart'' can be used over and over to carry numbers into the grid.&lt;br /&gt;
The result is show below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File : xpy.png | |center]]&lt;br /&gt;
&lt;br /&gt;
As for the square of integers in the upper left corner of the grid, it is “magic”; all rows, columns and diagonals have the same sum. Anyone venturing into wxGrid land is going to need all the magic he can get. But studying Barnum.cpp or other wxSmith code should be helpful. If it is hard to imagine how Smart and Hock could have thought that their very incomplete example was sufficient it is even more mind-boggling that BYO, the creator of wxSmith, was able to figure out what had to be done and to make it all so easily available.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9270</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9270"/>
		<updated>2017-02-07T16:34:25Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbe2s. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and numbers in some elements of a 20x30 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The code written by wxSmith itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by variables in your program. The code wxSmith writes has the size of the grid given by two constants, the number of rows and the number of columns, but you can easily see from that code how to make the grid's size depend on variables in your code. &lt;br /&gt;
    &lt;br /&gt;
So let's get started. Create a new wxWidgets application. Call it DiaGrid and make it frame-based. We don't want the grid showing all the time, only when we call it up, so we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid for the program.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40 (we will change it later in the code to 20 x 30); '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch. (This was discovered by a lot of trial and error.)&lt;br /&gt;
&lt;br /&gt;
Note that we did not put scroll bars on any of the components we used. The wxGrid component automatically carries its own scroll bars and any others just make for confusion.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of the created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog containing the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label some of the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for now.&lt;br /&gt;
&lt;br /&gt;
Now we can put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line. Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
&lt;br /&gt;
Let's now have a look at the code wxSmith has written for us. To avoid repetition, however, I will show the code after some additions by hand, but with clear markings distinguishing what wxSmith wrote from what was later added. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Barnum::Barnum(wxWindow* parent,wxWindowID id,const wxPoint&amp;amp; pos,const wxSize&amp;amp; size)&lt;br /&gt;
{&lt;br /&gt;
  //(*Initialize(Barnum)&lt;br /&gt;
  wxBoxSizer* BoxSizer2;&lt;br /&gt;
  wxBoxSizer* BoxSizer1;&lt;br /&gt;
  Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE |wxRESIZE_BORDER,  _T(&amp;quot;id&amp;quot;));&lt;br /&gt;
  SetClientSize(wxDefaultSize);&lt;br /&gt;
  Move(wxDefaultPosition);&lt;br /&gt;
  BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);&lt;br /&gt;
  Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T(&amp;quot;ID_PANEL1&amp;quot;));&lt;br /&gt;
  BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);&lt;br /&gt;
  Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(400,300), wxFULL_REPAINT_ON_RESIZE, _T(//*)&lt;br /&gt;
&lt;br /&gt;
//***End of Part 1. Everything above this line was written by wxSmith *******&lt;br /&gt;
&lt;br /&gt;
//                                  Part 2. &lt;br /&gt;
&lt;br /&gt;
// Now comes the hand-coded section (with a few lines borrowed from wxSmith)&lt;br /&gt;
&lt;br /&gt;
    int nrows, ncols;&lt;br /&gt;
    nrows =20; ncols = 30;&lt;br /&gt;
&lt;br /&gt;
    Grid1-&amp;gt;CreateGrid(nrows,ncols); // wxSmith had Grid1-&amp;gt;CreateGrid(40.40);&lt;br /&gt;
    Grid1-&amp;gt;EnableEditing(true);     // from wxSmith&lt;br /&gt;
    Grid1-&amp;gt;EnableGridLines(true);   // from wxSmith&lt;br /&gt;
// Label some columns&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;)); //from wxSmith &lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));  //from wxSmith &lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(2, _(&amp;quot;gamma&amp;quot;)); //from wxSmith &lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(3, _(&amp;quot;delta &amp;quot;));&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(4, _(&amp;quot;epsilon&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Label some rows&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(0, _(&amp;quot;mu&amp;quot;)); // from wxSmith&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(1, _(&amp;quot;nu&amp;quot;)); // from wxSmith&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(2, _(&amp;quot;xi&amp;quot;)); // from wxSmith&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(3, _(&amp;quot;omicron&amp;quot;));&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(4, _(&amp;quot;pi&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Column or row labels can be set from C-strings whose&lt;br /&gt;
// values are determined at runtime by first converting&lt;br /&gt;
// the C-string to a wxString, as illustrated here:&lt;br /&gt;
&lt;br /&gt;
    char colone[10];        //colone is the variable C-string.&lt;br /&gt;
    strcpy(colone,&amp;quot;omega&amp;quot;);// Give it some content at run time.&lt;br /&gt;
    wxString ColumnName;    // Define a wxString which may be used repeatedly.&lt;br /&gt;
// Convert contents of the C-string to a wxString:&lt;br /&gt;
    ColumnName = wxString::FromUTF8(colone);&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0,ColumnName); // Set the label for column 0.&lt;br /&gt;
&lt;br /&gt;
// Set some cell values&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 0, _(&amp;quot;2&amp;quot;)); //from wxSmith&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 1, _(&amp;quot;7&amp;quot;)); //from wxSmith&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 2, _(&amp;quot;6&amp;quot;)); //from wxSmith&lt;br /&gt;
&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Illustrate what SetColFormatFloat() does. From Smart &amp;amp; Hock, page 348 corrected.&lt;br /&gt;
	Grid1-&amp;gt;SetColFormatFloat(5,6,2); // Format numeric strings in column 5.&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0,5,_(&amp;quot;3.14159&amp;quot;)); // Put a number with 5 decimals there.&lt;br /&gt;
    // Put the same string in Column 4 for comparison.&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(0,4,_(&amp;quot;3.14159&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Here is how to show floats defined at run time in the wxGrid:&lt;br /&gt;
    float e = 2.71828;&lt;br /&gt;
    wxString cart;&lt;br /&gt;
    cart = wxString::Format(_T(&amp;quot;%f&amp;quot;), e);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1,4,cart);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1,5,cart);&lt;br /&gt;
&lt;br /&gt;
// Display a matrix of floats defined at run time.&lt;br /&gt;
    short i,j;&lt;br /&gt;
    float xx;&lt;br /&gt;
    for (i = 10; i &amp;lt;=12; i++){&lt;br /&gt;
        for (j = 10; j &amp;lt;= 12; j++){&lt;br /&gt;
            xx = i*j;&lt;br /&gt;
            xx = xx/2.;&lt;br /&gt;
            cart = wxString::Format(_T(&amp;quot;%8.2f&amp;quot;),xx);&lt;br /&gt;
            Grid1-&amp;gt;SetCellValue(i,j,cart);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
//&lt;br /&gt;
//                    *** Part 3 ***&lt;br /&gt;
// All that follows was written by wxSmith.&lt;br /&gt;
	Grid1-&amp;gt;SetDefaultCellFont( Grid1-&amp;gt;GetFont() );&lt;br /&gt;
	Grid1-&amp;gt;SetDefaultCellTextColour( Grid1-&amp;gt;GetForegroundColour() );&lt;br /&gt;
	BoxSizer2-&amp;gt;Add(Grid1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL| wxALIGN_CENTER_VERTICAL, 5);&lt;br /&gt;
	Panel1-&amp;gt;SetSizer(BoxSizer2);&lt;br /&gt;
	BoxSizer2-&amp;gt;Fit(Panel1);&lt;br /&gt;
	BoxSizer2-&amp;gt;SetSizeHints(Panel1);&lt;br /&gt;
	BoxSizer1-&amp;gt;Add(Panel1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);&lt;br /&gt;
	SetSizer(BoxSizer1);&lt;br /&gt;
	BoxSizer1-&amp;gt;Fit(this);&lt;br /&gt;
	BoxSizer1-&amp;gt;SetSizeHints(this);&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
wxSmith has separated its code into three parts – without, however, marking the divisions. I have added the division markers in the above listing. The first part has some preliminaries, the second part creates the grid and puts various values into it, and the third part attends to other matters whose precise function is elusive but presumably very necessary for the program to function properly. &lt;br /&gt;
&lt;br /&gt;
It is Part 2 that the programmer is likely to want to change. The first line of Part2 as written by wxSmith was: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The size of the grid may well not be known at compile time but depend on the matrix to be displayed. Somehow that variable size will be communicated to Barnum, perhaps by parameters in the call, perhaps by global variables, perhaps by a read from a file. To keep matters simple, I have represented that process by just defining nrows and ncols as ints in the code, but as far as the CreateGrid() function knows they came from somewhere else. So our Part2 begins:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    int nrows, ncols;&lt;br /&gt;
    nrows =20; ncols = 30;&lt;br /&gt;
    Grid1-&amp;gt;CreateGrid(nrows,ncols);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Just above these lines we need to mark the end of code that wxSmith controls. That end is marked by a  //*)  sign.  So this mark has been moved to precede these three lines. Part 1 of our code will therefore be everything down to and including this line.  The programmer should have no need to touch it save to allow Barnum to receive some variables from the program that calls it. &lt;br /&gt;
&lt;br /&gt;
We will use the same device for showing how to put floating point numbers known only at run time into the grid. We will define them as floats, and show how to put a float, no matter where it came from, into the grid. &lt;br /&gt;
&lt;br /&gt;
When it comes to displaying floating point numbers in the grid, however, we must deal with what appears to be an error in a couple of lines in the standard and most authoritative book on wxWidgets, ''Cross-Platform GUI Programming with wxWidgets'' by Smart and Hock. In the sole example given of a wxGrid, they write on page 348:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// We can specify that some cells will store numeric&lt;br /&gt;
// values rather than strings. Here we set grid column 5&lt;br /&gt;
// to hold floating point values displayed with width of 6&lt;br /&gt;
// and precision of 2&lt;br /&gt;
grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6, &amp;quot;3.1415&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This passage appears at least 18 times on the Internet without anyone observing that it is totally misleading if not dead wrong. To begin with, the last line is out of date and won't compile, at least not with Code::Blocks. It can be easily updated to:&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
But it does not illustrate the use of the SetColFormatFloat function. That command in the previous line applied to column 5 while this line puts a ''string'' – not a numeric value – into column 6, not 5. We can easily correct the column number:  &lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 5,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
But it is still putting a wxString – not a numeric value, and certainly not a float – into the cell.  It turns out that the assertion that “some cells will store numeric values rather than strings” is highly misleading at best. There is no elementary way to put anything other than a wxString into a cell of a wxGrid, nor to declare that a column will contain floats.  The function of SetColFormatFloat() is quite different. The command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is used to give a ''uniform appearance'' to the column. It makes all strings in column 5 representing numbers with decimal places appear with the same width and precision. Thus, after this command, the string “3.14159” in column 5 will appear as 3.14 and the string “3.1” will appear as 3.10.&lt;br /&gt;
&lt;br /&gt;
So then how do we show a floating point number in a wxGrid? We first have to convert it to a wxString and then put the string into the wxGrid. For example, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    float e = 2.71828; &lt;br /&gt;
    wxString cart; &lt;br /&gt;
    cart = wxString::Format(_T(&amp;quot;%f&amp;quot;), e);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart); &lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 5, cart); // To show what SetColFormatFloat does. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here ''cart'' is the wxString in which the numeric value of ''e'' rides into the grid. &lt;br /&gt;
Column or row labels can be set from C-strings whose values are determined at runtime by first converting the C-string to a wxString, as illustrated here:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    char colone[10];        //colone is the variable C-string.&lt;br /&gt;
    strcpy(colone,&amp;quot;alpha&amp;quot;);// Give it some content at run time.&lt;br /&gt;
    wxString ColumnName;    // Define a wxString which may be used repeatedly.&lt;br /&gt;
	 //Convert contents of the C-string to a wxString:&lt;br /&gt;
    ColumnName = wxString::FromUTF8(colone);&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0,ColumnName); // Set the column label.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When these lines have been added to Barnum and the code compiled and run, we get the result shown below.&lt;br /&gt;
&lt;br /&gt;
[[File : DiaGridFinal.png | |center|]]]&lt;br /&gt;
&lt;br /&gt;
Note that the floating point numbers appear with their full number of decimal places in column 4 (labeled &amp;quot;epsilon&amp;quot;)but in column 5 they have been rounded to 2 decimal places as a result of the SetColFormatFloat()  function.&lt;br /&gt;
&lt;br /&gt;
The last section of Part 2 shows how the wxString ''cart'' can be used over and over to carry numbers into the grid.&lt;br /&gt;
The result is show below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File : xpy.png | |center]]&lt;br /&gt;
&lt;br /&gt;
As for the square of integers in the upper left corner of the grid, it is “magic”; all rows, columns and diagonals have the same sum. Anyone venturing into wxGrid land is going to need all the magic he can get. But studying Barnum.cpp or other wxSmith code should be helpful. If it is hard to imagine how Smart and Hock could have thought that their very incomplete example was sufficient it is even more mind-boggling that BYO, the creator of wxSmith, was able to figure out what had to be done and to make it all so easily available.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9269</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9269"/>
		<updated>2017-02-07T16:14:34Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and numbers in some elements of a 40x40 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The code written by wxSmith itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by variables in your program. The code wxSmith writes has the size of the grid given by two constants, the number of rows and the number of columns, but you can easily see from that code how to make the grid's size depend on variables in your code. &lt;br /&gt;
    &lt;br /&gt;
So let's get started. Create a new wxWidgets application. Call it DiaGrid and make it frame-based. We don't want the grid showing all the time, only when we call it up, so we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid for the program.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch. (This was discovered by a lot of trial and error.)&lt;br /&gt;
&lt;br /&gt;
Note that we did not put scroll bars on any of the components we used. The wxGrid component automatically carries its own scroll bars and any others just make for confusion.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of the created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog containing the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label some of the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for now.&lt;br /&gt;
&lt;br /&gt;
Now we can put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line. Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
&lt;br /&gt;
Let's now have a look at the code wxSmith has written for us. To avoid repetition, however, I will show the code after some additions by hand, but with clear markings distinguishing what wxSmith wrote from what was later added. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Barnum::Barnum(wxWindow* parent,wxWindowID id,const wxPoint&amp;amp; pos,const wxSize&amp;amp; size)&lt;br /&gt;
{&lt;br /&gt;
  //(*Initialize(Barnum)&lt;br /&gt;
  wxBoxSizer* BoxSizer2;&lt;br /&gt;
  wxBoxSizer* BoxSizer1;&lt;br /&gt;
  Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE |wxRESIZE_BORDER,  _T(&amp;quot;id&amp;quot;));&lt;br /&gt;
  SetClientSize(wxDefaultSize);&lt;br /&gt;
  Move(wxDefaultPosition);&lt;br /&gt;
  BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);&lt;br /&gt;
  Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T(&amp;quot;ID_PANEL1&amp;quot;));&lt;br /&gt;
  BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);&lt;br /&gt;
  Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(400,300), wxFULL_REPAINT_ON_RESIZE, _T(//*)&lt;br /&gt;
&lt;br /&gt;
//***End of Part 1. Everything above this line was written by wxSmith *******&lt;br /&gt;
&lt;br /&gt;
//                                  Part 2. &lt;br /&gt;
&lt;br /&gt;
// Now comes the hand-coded section (with a few lines borrowed from wxSmith)&lt;br /&gt;
&lt;br /&gt;
    int nrows, ncols;&lt;br /&gt;
    nrows =20; ncols = 30;&lt;br /&gt;
&lt;br /&gt;
    Grid1-&amp;gt;CreateGrid(nrows,ncols); // wxSmith had Grid1-&amp;gt;CreateGrid(40.40);&lt;br /&gt;
    Grid1-&amp;gt;EnableEditing(true);     // from wxSmith&lt;br /&gt;
    Grid1-&amp;gt;EnableGridLines(true);   // from wxSmith&lt;br /&gt;
// Label some columns&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;)); //from wxSmith &lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));  //from wxSmith &lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(2, _(&amp;quot;gamma&amp;quot;)); //from wxSmith &lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(3, _(&amp;quot;delta &amp;quot;));&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(4, _(&amp;quot;epsilon&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Label some rows&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(0, _(&amp;quot;mu&amp;quot;)); // from wxSmith&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(1, _(&amp;quot;nu&amp;quot;)); // from wxSmith&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(2, _(&amp;quot;xi&amp;quot;)); // from wxSmith&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(3, _(&amp;quot;omicron&amp;quot;));&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(4, _(&amp;quot;pi&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Column or row labels can be set from C-strings whose&lt;br /&gt;
// values are determined at runtime by first converting&lt;br /&gt;
// the C-string to a wxString, as illustrated here:&lt;br /&gt;
&lt;br /&gt;
    char colone[10];        //colone is the variable C-string.&lt;br /&gt;
    strcpy(colone,&amp;quot;alpha2&amp;quot;);// Give it some content at run time.&lt;br /&gt;
    wxString ColumnName;    // Define a wxString which may be used repeatedly.&lt;br /&gt;
// Convert contents of the C-string to a wxString:&lt;br /&gt;
    ColumnName = wxString::FromUTF8(colone);&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0,ColumnName); // Set the column label.&lt;br /&gt;
&lt;br /&gt;
// Set some cell values&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 0, _(&amp;quot;2&amp;quot;)); //from wxSmith&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 1, _(&amp;quot;7&amp;quot;)); //from wxSmith&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 2, _(&amp;quot;6&amp;quot;)); //from wxSmith&lt;br /&gt;
&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Illustrate what SetColFormatFloat() does. From Smart &amp;amp; Hock, page 348 corrected.&lt;br /&gt;
	Grid1-&amp;gt;SetColFormatFloat(5,6,2); // Format numeric strings in column 5.&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0,5,_(&amp;quot;3.14159&amp;quot;)); // Put a number with 5 decimals there.&lt;br /&gt;
    // Put the same string in Column 4 for comparison.&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(0,4,_(&amp;quot;3.14159&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Here is how to show floats defined at run time in the wxGrid:&lt;br /&gt;
    float e = 2.71828;&lt;br /&gt;
    wxString cart;&lt;br /&gt;
    cart = wxString::Format(_T(&amp;quot;%f&amp;quot;), e);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1,4,cart);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1,5,cart);&lt;br /&gt;
&lt;br /&gt;
// Display a matrix of floats defined at run time.&lt;br /&gt;
    short i,j;&lt;br /&gt;
    float xx;&lt;br /&gt;
    for (i = 10; i &amp;lt;=12; i++){&lt;br /&gt;
        for (j = 10; j &amp;lt;= 12; j++){&lt;br /&gt;
            xx = i*j;&lt;br /&gt;
            xx = xx/2.;&lt;br /&gt;
            cart = wxString::Format(_T(&amp;quot;%8.2f&amp;quot;),xx);&lt;br /&gt;
            Grid1-&amp;gt;SetCellValue(i,j,cart);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
//&lt;br /&gt;
//                    *** Part 3 ***&lt;br /&gt;
// All that follows was written by wxSmith.&lt;br /&gt;
	Grid1-&amp;gt;SetDefaultCellFont( Grid1-&amp;gt;GetFont() );&lt;br /&gt;
	Grid1-&amp;gt;SetDefaultCellTextColour( Grid1-&amp;gt;GetForegroundColour() );&lt;br /&gt;
	BoxSizer2-&amp;gt;Add(Grid1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL| wxALIGN_CENTER_VERTICAL, 5);&lt;br /&gt;
	Panel1-&amp;gt;SetSizer(BoxSizer2);&lt;br /&gt;
	BoxSizer2-&amp;gt;Fit(Panel1);&lt;br /&gt;
	BoxSizer2-&amp;gt;SetSizeHints(Panel1);&lt;br /&gt;
	BoxSizer1-&amp;gt;Add(Panel1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);&lt;br /&gt;
	SetSizer(BoxSizer1);&lt;br /&gt;
	BoxSizer1-&amp;gt;Fit(this);&lt;br /&gt;
	BoxSizer1-&amp;gt;SetSizeHints(this);&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
wxSmith has separated its code into three parts – without, however, marking the divisions. I have added the division markers in the above listing. The first part has some preliminaries, the second part creates the grid and puts various values into it, and the third part attends to other matters whose precise function is elusive but presumably very necessary for the program to function properly. &lt;br /&gt;
&lt;br /&gt;
It is Part 2 that the programmer is likely to want to change. The first line of Part2 as written by wxSmith was: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The size of the grid may well not be known at compile time but depend on the matrix to be displayed. Somehow that variable size will be communicated to Barnum, perhaps by parameters in the call, perhaps by global variables, perhaps by a read from a file. To keep matters simple, I have represented that process by just defining nrows and ncols as ints in the code, but as far as the CreateGrid() function knows they came from somewhere else. So our Part2 begins:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    int nrows, ncols;&lt;br /&gt;
    nrows =20; ncols = 30;&lt;br /&gt;
    Grid1-&amp;gt;CreateGrid(nrows,ncols);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Just above these lines we need to mark the end of code that wxSmith controls. That end is marked by a  //*)  sign.  So this mark has been moved to precede these three lines. Part 1 of our code will therefore be everything down to and including this line.  The programmer should have no need to touch it save to allow Barnum to receive some variables from the program that calls it. &lt;br /&gt;
&lt;br /&gt;
We will use the same device for showing how to put floating point numbers known only at run time into the grid. We will define them as floats, and show how to put a float, no matter where it came from, into the grid. &lt;br /&gt;
&lt;br /&gt;
When it comes to displaying floating point numbers in the grid, however, we must deal with what appears to be an error in a couple of lines in the standard and most authoritative book on wxWidgets, ''Cross-Platform GUI Programming with wxWidgets'' by Smart and Hock. In the sole example given of a wxGrid, they write on page 348:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// We can specify that some cells will store numeric&lt;br /&gt;
// values rather than strings. Here we set grid column 5&lt;br /&gt;
// to hold floating point values displayed with width of 6&lt;br /&gt;
// and precision of 2&lt;br /&gt;
grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6, &amp;quot;3.1415&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This passage appears at least 18 times on the Internet without anyone observing that it is totally misleading if not dead wrong. To begin with, the last line is out of date and won't compile, at least not with Code::Blocks. It can be easily updated to:&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
But it does not illustrate the use of the SetColFormatFloat function. That command in the previous line applied to column 5 while this line puts a ''string'' – not a numeric value – into column 6, not 5. We can easily correct the column number:  &lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 5,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
But it is still putting a wxString – not a numeric value, and certainly not a float – into the cell.  It turns out that the assertion that “some cells will store numeric values rather than strings” is highly misleading at best. There is no elementary way to put anything other than a wxString into a cell of a wxGrid, nor to declare that a column will contain floats.  The function of SetColFormatFloat() is quite different. The command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is used to give a ''uniform appearance'' to the column. It makes all strings in column 5 representing numbers with decimal places appear with the same width and precision. Thus, after this command, the string “3.14159” in column 5 will appear as 3.14 and the string “3.1” will appear as 3.10.&lt;br /&gt;
&lt;br /&gt;
So then how do we show a floating point number in a wxGrid? We first have to convert it to a wxString and then put the string into the wxGrid. For example, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    float e = 2.71828; &lt;br /&gt;
    wxString cart; &lt;br /&gt;
    cart = wxString::Format(_T(&amp;quot;%f&amp;quot;), e);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart); &lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 5, cart); // To show what SetColFormatFloat does. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here ''cart'' is the wxString in which the numeric value of ''e'' rides into the grid. &lt;br /&gt;
Column or row labels can be set from C-strings whose values are determined at runtime by first converting the C-string to a wxString, as illustrated here:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    char colone[10];        //colone is the variable C-string.&lt;br /&gt;
    strcpy(colone,&amp;quot;alpha&amp;quot;);// Give it some content at run time.&lt;br /&gt;
    wxString ColumnName;    // Define a wxString which may be used repeatedly.&lt;br /&gt;
	 //Convert contents of the C-string to a wxString:&lt;br /&gt;
    ColumnName = wxString::FromUTF8(colone);&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0,ColumnName); // Set the column label.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When these lines have been added to Barnum and the code compiled and run, we get the result shown below.&lt;br /&gt;
&lt;br /&gt;
[[File : DiaGridFinal.png | |center|]]]&lt;br /&gt;
&lt;br /&gt;
Note that the floating point numbers appear with their full number of decimal places in column 4 (labeled &amp;quot;epsilon&amp;quot;)but in column 5 they have been rounded to 2 decimal places as a result of the SetColFormatFloat()  function.&lt;br /&gt;
&lt;br /&gt;
The last section of Part 2 shows how the wxString ''cart'' can be used over and over to carry numbers into the grid.&lt;br /&gt;
The result is show below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File : xpy.png | |center]]&lt;br /&gt;
&lt;br /&gt;
As for the square of integers in the upper left corner of the grid, it is “magic”; all rows, columns and diagonals have the same sum. Anyone venturing into wxGrid land is going to need all the magic he can get. But studying Barnum.cpp or other wxSmith code should be helpful. If it is hard to imagine how Smart and Hock could have thought that their very incomplete example was sufficient it is even more mind-boggling that BYO, the creator of wxSmith, was able to figure out what had to be done and to make it all so easily available.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9268</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9268"/>
		<updated>2017-02-05T22:47:16Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and values numeric values in some elements of a 40x40 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The code written by wxSmith itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by variables in your program. The code wxSmith writes has the size of the grid given by two constants, the number of rows and the number of columns, but you can easily see from that code how to make the grid's size depend on variables in your code. &lt;br /&gt;
    &lt;br /&gt;
So let's get started. Create a new wxWidgets application. Call it DiaGrid and make it frame-based. We don't want the grid showing all the time, only when we call it up, so we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid for the program.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch. (This was discovered by a lot of trial and error.)&lt;br /&gt;
&lt;br /&gt;
Note that we did not put scroll bars on any of the components we used. The wxGrid component automatically carries its own scroll bars and any others just make for confusion.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of the created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog containing the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label some of the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for now.&lt;br /&gt;
&lt;br /&gt;
Now we can put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line. Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
&lt;br /&gt;
Let's now have a look at the code wxSmith has written for us. To avoid repetition, however, I will show the code after some additions by hand, but with clear markings distinguishing what wxSmith wrote from what was later added. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Barnum::Barnum(wxWindow* parent,wxWindowID id,const wxPoint&amp;amp; pos,const wxSize&amp;amp; size)&lt;br /&gt;
{&lt;br /&gt;
  //(*Initialize(Barnum)&lt;br /&gt;
  wxBoxSizer* BoxSizer2;&lt;br /&gt;
  wxBoxSizer* BoxSizer1;&lt;br /&gt;
  Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE |wxRESIZE_BORDER,  _T(&amp;quot;id&amp;quot;));&lt;br /&gt;
  SetClientSize(wxDefaultSize);&lt;br /&gt;
  Move(wxDefaultPosition);&lt;br /&gt;
  BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);&lt;br /&gt;
  Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T(&amp;quot;ID_PANEL1&amp;quot;));&lt;br /&gt;
  BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);&lt;br /&gt;
  Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(400,300), wxFULL_REPAINT_ON_RESIZE, _T(//*)&lt;br /&gt;
&lt;br /&gt;
//***End of Part 1. Everything above this line was written by wxSmith *******&lt;br /&gt;
&lt;br /&gt;
//                                  Part 2. &lt;br /&gt;
&lt;br /&gt;
// Now comes the hand-coded section (with a few lines borrowed from wxSmith)&lt;br /&gt;
&lt;br /&gt;
    int nrows, ncols;&lt;br /&gt;
    nrows =20; ncols = 30;&lt;br /&gt;
&lt;br /&gt;
    Grid1-&amp;gt;CreateGrid(nrows,ncols); // wxSmith had Grid1-&amp;gt;CreateGrid(40.40);&lt;br /&gt;
    Grid1-&amp;gt;EnableEditing(true);     // from wxSmith&lt;br /&gt;
    Grid1-&amp;gt;EnableGridLines(true);   // from wxSmith&lt;br /&gt;
// Label some columns&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;)); //from wxSmith &lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));  //from wxSmith &lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(2, _(&amp;quot;gamma&amp;quot;)); //from wxSmith &lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(3, _(&amp;quot;delta &amp;quot;));&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(4, _(&amp;quot;epsilon&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Label some rows&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(0, _(&amp;quot;mu&amp;quot;)); // from wxSmith&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(1, _(&amp;quot;nu&amp;quot;)); // from wxSmith&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(2, _(&amp;quot;xi&amp;quot;)); // from wxSmith&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(3, _(&amp;quot;omicron&amp;quot;));&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(4, _(&amp;quot;pi&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Column or row labels can be set from C-strings whose&lt;br /&gt;
// values are determined at runtime by first converting&lt;br /&gt;
// the C-string to a wxString, as illustrated here:&lt;br /&gt;
&lt;br /&gt;
    char colone[10];        //colone is the variable C-string.&lt;br /&gt;
    strcpy(colone,&amp;quot;alpha2&amp;quot;);// Give it some content at run time.&lt;br /&gt;
    wxString ColumnName;    // Define a wxString which may be used repeatedly.&lt;br /&gt;
// Convert contents of the C-string to a wxString:&lt;br /&gt;
    ColumnName = wxString::FromUTF8(colone);&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0,ColumnName); // Set the column label.&lt;br /&gt;
&lt;br /&gt;
// Set some cell values&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 0, _(&amp;quot;2&amp;quot;)); //from wxSmith&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 1, _(&amp;quot;7&amp;quot;)); //from wxSmith&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 2, _(&amp;quot;6&amp;quot;)); //from wxSmith&lt;br /&gt;
&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Illustrate what SetColFormatFloat() does. From Smart &amp;amp; Hock, page 348 corrected.&lt;br /&gt;
	Grid1-&amp;gt;SetColFormatFloat(5,6,2); // Format numeric strings in column 5.&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0,5,_(&amp;quot;3.14159&amp;quot;)); // Put a number with 5 decimals there.&lt;br /&gt;
    // Put the same string in Column 4 for comparison.&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(0,4,_(&amp;quot;3.14159&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Here is how to show floats defined at run time in the wxGrid:&lt;br /&gt;
    float e = 2.71828;&lt;br /&gt;
    wxString cart;&lt;br /&gt;
    cart = wxString::Format(_T(&amp;quot;%f&amp;quot;), e);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1,4,cart);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1,5,cart);&lt;br /&gt;
&lt;br /&gt;
// Display a matrix of floats defined at run time.&lt;br /&gt;
    short i,j;&lt;br /&gt;
    float xx;&lt;br /&gt;
    for (i = 10; i &amp;lt;=12; i++){&lt;br /&gt;
        for (j = 10; j &amp;lt;= 12; j++){&lt;br /&gt;
            xx = i*j;&lt;br /&gt;
            xx = xx/2.;&lt;br /&gt;
            cart = wxString::Format(_T(&amp;quot;%8.2f&amp;quot;),xx);&lt;br /&gt;
            Grid1-&amp;gt;SetCellValue(i,j,cart);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
//&lt;br /&gt;
//                    *** Part 3 ***&lt;br /&gt;
// All that follows was written by wxSmith.&lt;br /&gt;
	Grid1-&amp;gt;SetDefaultCellFont( Grid1-&amp;gt;GetFont() );&lt;br /&gt;
	Grid1-&amp;gt;SetDefaultCellTextColour( Grid1-&amp;gt;GetForegroundColour() );&lt;br /&gt;
	BoxSizer2-&amp;gt;Add(Grid1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL| wxALIGN_CENTER_VERTICAL, 5);&lt;br /&gt;
	Panel1-&amp;gt;SetSizer(BoxSizer2);&lt;br /&gt;
	BoxSizer2-&amp;gt;Fit(Panel1);&lt;br /&gt;
	BoxSizer2-&amp;gt;SetSizeHints(Panel1);&lt;br /&gt;
	BoxSizer1-&amp;gt;Add(Panel1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);&lt;br /&gt;
	SetSizer(BoxSizer1);&lt;br /&gt;
	BoxSizer1-&amp;gt;Fit(this);&lt;br /&gt;
	BoxSizer1-&amp;gt;SetSizeHints(this);&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
wxSmith has separated its code into three parts – without, however, marking the divisions. I have added the division markers in the above listing. The first part has some preliminaries, the second part creates the grid and puts various values into it, and the third part attends to other matters whose precise function is elusive but presumably very necessary for the program to function properly. &lt;br /&gt;
&lt;br /&gt;
It is Part 2 that the programmer is likely to want to change. The first line of Part2 as written by wxSmith was: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The size of the grid may well not be known at compile time but depend on the matrix to be displayed. Somehow that variable size will be communicated to Barnum, perhaps by parameters in the call, perhaps by global variables, perhaps by a read from a file. To keep matters simple, I have represented that process by just defining nrows and ncols as ints in the code, but as far as the CreateGrid() function knows they came from somewhere else. So our Part2 begins:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    int nrows, ncols;&lt;br /&gt;
    nrows =20; ncols = 30;&lt;br /&gt;
    Grid1-&amp;gt;CreateGrid(nrows,ncols);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Just above these lines we need to mark the end of code that wxSmith controls. That end is marked by a  //*)  sign.  So this mark has been moved to precede these three lines. Part 1 of our code will therefore be everything down to and including this line.  The programmer should have no need to touch it save to allow Barnum to receive some variables from the program that calls it. &lt;br /&gt;
&lt;br /&gt;
We will use the same device for showing how to put floating point numbers known only at run time into the grid. We will define them as floats, and show how to put a float, no matter where it came from, into the grid. &lt;br /&gt;
&lt;br /&gt;
When it comes to displaying floating point numbers in the grid, however, we must deal with what appears to be an error in a couple of lines in the standard and most authoritative book on wxWidgets, ''Cross-Platform GUI Programming with wxWidgets'' by Smart and Hock. In the sole example given of a wxGrid, they write on page 348:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// We can specify that some cells will store numeric&lt;br /&gt;
// values rather than strings. Here we set grid column 5&lt;br /&gt;
// to hold floating point values displayed with width of 6&lt;br /&gt;
// and precision of 2&lt;br /&gt;
grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6, &amp;quot;3.1415&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This passage appears at least 18 times on the Internet without anyone observing that it is totally misleading if not dead wrong. To begin with, the last line is out of date and won't compile, at least not with Code::Blocks. It can be easily updated to:&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
But it does not illustrate the use of the SetColFormatFloat function. That command in the previous line applied to column 5 while this line puts a ''string'' – not a numeric value – into column 6, not 5. We can easily correct the column number:  &lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 5,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
But it is still putting a wxString – not a numeric value, and certainly not a float – into the cell.  It turns out that the assertion that “some cells will store numeric values rather than strings” is highly misleading at best. There is no elementary way to put anything other than a wxString into a cell of a wxGrid, nor to declare that a column will contain floats.  The function of SetColFormatFloat() is quite different. The command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is used to give a ''uniform appearance'' to the column. It makes all strings in column 5 representing numbers with decimal places appear with the same width and precision. Thus, after this command, the string “3.14159” in column 5 will appear as 3.14 and the string “3.1” will appear as 3.10.&lt;br /&gt;
&lt;br /&gt;
So then how do we show a floating point number in a wxGrid? We first have to convert it to a wxString and then put the string into the wxGrid. For example, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    float e = 2.71828; &lt;br /&gt;
    wxString cart; &lt;br /&gt;
    cart = wxString::Format(_T(&amp;quot;%f&amp;quot;), e);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart); &lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 5, cart); // To show what SetColFormatFloat does. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here ''cart'' is the wxString in which the numeric value of ''e'' rides into the grid. &lt;br /&gt;
Column or row labels can be set from C-strings whose values are determined at runtime by first converting the C-string to a wxString, as illustrated here:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    char colone[10];        //colone is the variable C-string.&lt;br /&gt;
    strcpy(colone,&amp;quot;alpha&amp;quot;);// Give it some content at run time.&lt;br /&gt;
    wxString ColumnName;    // Define a wxString which may be used repeatedly.&lt;br /&gt;
	 //Convert contents of the C-string to a wxString:&lt;br /&gt;
    ColumnName = wxString::FromUTF8(colone);&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0,ColumnName); // Set the column label.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When these lines have been added to Barnum and the code compiled and run, we get the result shown below.&lt;br /&gt;
&lt;br /&gt;
[[File : DiaGridFinal.png | |center|]]]&lt;br /&gt;
&lt;br /&gt;
Note that the floating point numbers appear with their full number of decimal places in column 4 (labeled &amp;quot;epsilon&amp;quot;)but in column 5 they have been rounded to 2 decimal places as a result of the SetColFormatFloat()  function.&lt;br /&gt;
&lt;br /&gt;
The last section of Part 2 shows how the wxString ''cart'' can be used over and over to carry numbers into the grid.&lt;br /&gt;
The result is show below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File : xpy.png | |center]]&lt;br /&gt;
&lt;br /&gt;
As for the square of integers in the upper left corner of the grid, it is “magic”; all rows, columns and diagonals have the same sum. Anyone venturing into wxGrid land is going to need all the magic he can get. But studying Barnum.cpp or other wxSmith code should be helpful. If it is hard to imagine how Smart and Hock could have thought that their very incomplete example was sufficient it is even more mind-boggling that BYO, the creator of wxSmith, was able to figure out what had to be done and to make it all so easily available.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9267</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9267"/>
		<updated>2017-02-05T22:36:30Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and values numeric values in some elements of a 40x40 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The code written by wxSmith itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by variables in your program. The code wxSmith writes has the size of the grid given by two constants, the number of rows and the number of columns, but you can easily see from that code how to make the grid's size depend on variables in your code. &lt;br /&gt;
    &lt;br /&gt;
So let's get started. Create a new wxWidgets application. Call it DiaGrid and make it frame-based. We don't want the grid showing all the time, only when we call it up, so we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid for the program.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch. (This was discovered by a lot of trial and error.)&lt;br /&gt;
&lt;br /&gt;
Note that we did not put scroll bars on any of the components we used. The wxGrid component automatically carries its own scroll bars and any others just make for confusion.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of the created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog containing the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label some of the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for now.&lt;br /&gt;
&lt;br /&gt;
Now we can put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line. Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
&lt;br /&gt;
Let's now have a look at the code wxSmith has written for us. To avoid repetition, however, I will show the code after some additions by hand, but with clear markings distinguishing what wxSmith wrote from what was later added. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Barnum::Barnum(wxWindow* parent,wxWindowID id,const wxPoint&amp;amp; pos,const wxSize&amp;amp; size)&lt;br /&gt;
{&lt;br /&gt;
  //(*Initialize(Barnum)&lt;br /&gt;
  wxBoxSizer* BoxSizer2;&lt;br /&gt;
  wxBoxSizer* BoxSizer1;&lt;br /&gt;
  Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE |wxRESIZE_BORDER,  _T(&amp;quot;id&amp;quot;));&lt;br /&gt;
  SetClientSize(wxDefaultSize);&lt;br /&gt;
  Move(wxDefaultPosition);&lt;br /&gt;
  BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);&lt;br /&gt;
  Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T(&amp;quot;ID_PANEL1&amp;quot;));&lt;br /&gt;
  BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);&lt;br /&gt;
  Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(400,300), wxFULL_REPAINT_ON_RESIZE, _T(//*)&lt;br /&gt;
&lt;br /&gt;
//***End of Part 1. Everything above this line was written by wxSmith *******&lt;br /&gt;
&lt;br /&gt;
//                                  Part 2. &lt;br /&gt;
&lt;br /&gt;
// Now comes the hand-coded section (with a few lines borrowed from wxSmith)&lt;br /&gt;
&lt;br /&gt;
    int nrows, ncols;&lt;br /&gt;
    nrows =20; ncols = 30;&lt;br /&gt;
&lt;br /&gt;
    Grid1-&amp;gt;CreateGrid(nrows,ncols); // wxSmith had Grid1-&amp;gt;CreateGrid(40.40);&lt;br /&gt;
    Grid1-&amp;gt;EnableEditing(true);     // from wxSmith&lt;br /&gt;
    Grid1-&amp;gt;EnableGridLines(true);   // from wxSmith&lt;br /&gt;
// Label some columns&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;)); //from wxSmith &lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));  //from wxSmith &lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(2, _(&amp;quot;gamma&amp;quot;)); //from wxSmith &lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(3, _(&amp;quot;delta &amp;quot;));&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(4, _(&amp;quot;epsilon&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Label some rows&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(0, _(&amp;quot;mu&amp;quot;)); // from wxSmith&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(1, _(&amp;quot;nu&amp;quot;)); // from wxSmith&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(2, _(&amp;quot;xi&amp;quot;)); // from wxSmith&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(3, _(&amp;quot;omicron&amp;quot;));&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(4, _(&amp;quot;pi&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Column or row labels can be set from C-strings whose&lt;br /&gt;
// values are determined at runtime by first converting&lt;br /&gt;
// the C-string to a wxString, as illustrated here:&lt;br /&gt;
&lt;br /&gt;
    char colone[10];        //colone is the variable C-string.&lt;br /&gt;
    strcpy(colone,&amp;quot;alpha2&amp;quot;);// Give it some content at run time.&lt;br /&gt;
    wxString ColumnName;    // Define a wxString which may be used repeatedly.&lt;br /&gt;
// Convert contents of the C-string to a wxString:&lt;br /&gt;
    ColumnName = wxString::FromUTF8(colone);&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0,ColumnName); // Set the column label.&lt;br /&gt;
&lt;br /&gt;
// Set some cell values&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 0, _(&amp;quot;2&amp;quot;)); //from wxSmith&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 1, _(&amp;quot;7&amp;quot;)); //from wxSmith&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 2, _(&amp;quot;6&amp;quot;)); //from wxSmith&lt;br /&gt;
&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Illustrate what SetColFormatFloat() does. From Smart &amp;amp; Hock, page 348 corrected.&lt;br /&gt;
	Grid1-&amp;gt;SetColFormatFloat(5,6,2); // Format numeric strings in column 5.&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0,5,_(&amp;quot;3.14159&amp;quot;)); // Put a number with 5 decimals there.&lt;br /&gt;
    // Put the same string in Column 4 for comparison.&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(0,4,_(&amp;quot;3.14159&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Here is how to show floats defined at run time in the wxGrid:&lt;br /&gt;
    float e = 2.71828;&lt;br /&gt;
    wxString cart;&lt;br /&gt;
    cart = wxString::Format(_T(&amp;quot;%f&amp;quot;), e);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1,4,cart);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1,5,cart);&lt;br /&gt;
&lt;br /&gt;
// Display a matrix of floats defined at run time.&lt;br /&gt;
    short i,j;&lt;br /&gt;
    float xx;&lt;br /&gt;
    for (i = 10; i &amp;lt;=12; i++){&lt;br /&gt;
        for (j = 10; j &amp;lt;= 12; j++){&lt;br /&gt;
            xx = i*j;&lt;br /&gt;
            xx = xx/2.;&lt;br /&gt;
            cart = wxString::Format(_T(&amp;quot;%8.2f&amp;quot;),xx);&lt;br /&gt;
            Grid1-&amp;gt;SetCellValue(i,j,cart);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
//&lt;br /&gt;
//                    *** Part 3 ***&lt;br /&gt;
// All that follows was written by wxSmith.&lt;br /&gt;
	Grid1-&amp;gt;SetDefaultCellFont( Grid1-&amp;gt;GetFont() );&lt;br /&gt;
	Grid1-&amp;gt;SetDefaultCellTextColour( Grid1-&amp;gt;GetForegroundColour() );&lt;br /&gt;
	BoxSizer2-&amp;gt;Add(Grid1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL| wxALIGN_CENTER_VERTICAL, 5);&lt;br /&gt;
	Panel1-&amp;gt;SetSizer(BoxSizer2);&lt;br /&gt;
	BoxSizer2-&amp;gt;Fit(Panel1);&lt;br /&gt;
	BoxSizer2-&amp;gt;SetSizeHints(Panel1);&lt;br /&gt;
	BoxSizer1-&amp;gt;Add(Panel1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);&lt;br /&gt;
	SetSizer(BoxSizer1);&lt;br /&gt;
	BoxSizer1-&amp;gt;Fit(this);&lt;br /&gt;
	BoxSizer1-&amp;gt;SetSizeHints(this);&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
wxSmith has separated its code into three parts – without, however, marking the divisions. I have added the division markers in the above listing. The first part has some preliminaries, the second part creates the grid and puts various values into it, and the third part attends to other matters whose precise function is elusive but presumably very necessary for the program to function properly. &lt;br /&gt;
&lt;br /&gt;
It is Part 2 that the programmer is likely to want to change. The first line of Part2 as written by wxSmith was: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The size of the grid may well not be known at compile time but depend on the matrix to be displayed. Somehow that variable size will be communicated to Barnum, perhaps by parameters in the call, perhaps by global variables, perhaps by a read from a file. To keep matters simple, I have represented that process by just defining nrows and ncols as ints in the code, but as far as the CreateGrid() function knows they came from somewhere else. So our Part2 begins:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    int nrows, ncols;&lt;br /&gt;
    nrows =20; ncols = 30;&lt;br /&gt;
    Grid1-&amp;gt;CreateGrid(nrows,ncols);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Just above these lines we need to mark the end of code that wxSmith controls. That end is marked by a  //*)  sign.  So this mark has been moved to precede these three lines. Part 1 of our code will therefore be everything down to and including this line.  The programmer should have no need to touch it save to allow Barnum to receive some variables from the program that calls it. &lt;br /&gt;
&lt;br /&gt;
We will use the same device for showing how to put floating point numbers known only at run time into the grid. We will define them as floats, and show how to put a float, no matter where it came from, into the grid. &lt;br /&gt;
&lt;br /&gt;
When it comes to displaying floating point numbers in the grid, however, we must deal with what appears to be an error in a couple of lines in the standard and most authoritative book on wxWidgets, ''Cross-Platform GUI Programming with wxWidgets'' by Smart and Hock. In the sole example given of a wxGrid, they write on page 348:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// We can specify that some cells will store numeric&lt;br /&gt;
// values rather than strings. Here we set grid column 5&lt;br /&gt;
// to hold floating point values displayed with width of 6&lt;br /&gt;
// and precision of 2&lt;br /&gt;
grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6, &amp;quot;3.1415&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This passage appears at least 18 times on the Internet without anyone observing that it is totally misleading if not dead wrong. To begin with, the last line is out of date and won't compile, at least not with Code::Blocks. It can be easily updated to:&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
But it does not illustrate the use of the SetColFormatFloat function. That command in the previous line applied to column 5 while this line puts a ''string'' – not a numeric value – into column 6, not 5. We can easily correct the column number:  &lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 5,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
But it is still putting a wxString – not a numeric value, and certainly not a float – into the cell.  It turns out that the assertion that “some cells will store numeric values rather than strings” is highly misleading at best. There is no elementary way to put anything other than a wxString into a cell of a wxGrid, nor to declare that a column will contain floats.  The function of SetColFormatFloat() is quite different. The command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is used to give a ''uniform appearance'' to the column. It makes all strings in column 5 representing numbers with decimal places appear with the same width and precision. Thus, after this command, the string “3.14159” in column 5 will appear as 3.14 and the string “3.1” will appear as 3.10.&lt;br /&gt;
&lt;br /&gt;
So then how do we show a floating point number in a wxGrid? We first have to convert it to a wxString and then put the string into the wxGrid. For example, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    float e = 2.71828; &lt;br /&gt;
    wxString cart; &lt;br /&gt;
    cart = wxString::Format(_T(&amp;quot;%f&amp;quot;), e);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart); &lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 5, cart); // To show what SetColFormatFloat does. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here ''cart'' is the wxString in which the numeric value of ''e'' rides into the grid. &lt;br /&gt;
Column or row labels can be set from C-strings whose values are determined at runtime by first converting the C-string to a wxString, as illustrated here:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    char colone[10];        //colone is the variable C-string.&lt;br /&gt;
    strcpy(colone,&amp;quot;alpha&amp;quot;);// Give it some content at run time.&lt;br /&gt;
    wxString ColumnName;    // Define a wxString which may be used repeatedly.&lt;br /&gt;
	 //Convert contents of the C-string to a wxString:&lt;br /&gt;
    ColumnName = wxString::FromUTF8(colone);&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0,ColumnName); // Set the column label.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When these lines have been added to Barnum and the code compiled and run, we get the result shown below.&lt;br /&gt;
&lt;br /&gt;
[[File : DiaGridFinal.png | |center|]]]&lt;br /&gt;
&lt;br /&gt;
Note that the floating point numbers appear with their full number of decimal places in column 4 (labeled &amp;quot;epsilon&amp;quot;)but in column 5 they have been rounded to 2 decimal places as a result of the SetColFormatFloat()  function.&lt;br /&gt;
&lt;br /&gt;
The last section of Part 2 shows how the wxString ''cart'' can be used over and over to carry numbers into the grid.&lt;br /&gt;
The result is show below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The result is shown below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
&lt;br /&gt;
[[File : xpy.png | |center]]&lt;br /&gt;
&lt;br /&gt;
As for the square of integers in the upper left corner of the grid, it is “magic”; all rows, columns and diagonals have the same sum. Anyone venturing into wxGrid land is going to need all the magic he can get. But studying Barnum.cpp or other wxSmith code should be helpful. If it is hard to imagine how Smart and Hock could have thought that their very incomplete example was sufficient it is even more mind-boggling that BYO, the creator of wxSmith, was able to figure out what had to be done and make it all so easily available.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9265</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9265"/>
		<updated>2017-02-05T22:16:36Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and values numeric values in some elements of a 40x40 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The code written by wxSmith itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by variables in your program. The code wxSmith writes has the size of the grid given by two constants, the number of rows and the number of columns, but you can easily see from that code how to make the grid's size depend on variables in your code. &lt;br /&gt;
    &lt;br /&gt;
So let's get started. Create a new wxWidgets application. Call it DiaGrid and make it frame-based. We don't want the grid showing all the time, only when we call it up, so we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid for the program.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch. (This was discovered by a lot of trial and error.)&lt;br /&gt;
&lt;br /&gt;
Note that we did not put scroll bars on any of the components we used. The wxGrid component automatically carries its own scroll bars and any others just make for confusion.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog containing the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label some of the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for now.&lt;br /&gt;
&lt;br /&gt;
Now we can put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line. Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
&lt;br /&gt;
Let's now have a look at the code wxSmith has written for us. To avoid repetition, however, I will show the code after some additions by hand, but with clear markings distinguishing what wxSmith wrote from what was later added. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Barnum::Barnum(wxWindow* parent,wxWindowID id,const wxPoint&amp;amp; pos,const wxSize&amp;amp; size)&lt;br /&gt;
{&lt;br /&gt;
  //(*Initialize(Barnum)&lt;br /&gt;
  wxBoxSizer* BoxSizer2;&lt;br /&gt;
  wxBoxSizer* BoxSizer1;&lt;br /&gt;
  Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE |wxRESIZE_BORDER,  _T(&amp;quot;id&amp;quot;));&lt;br /&gt;
  SetClientSize(wxDefaultSize);&lt;br /&gt;
  Move(wxDefaultPosition);&lt;br /&gt;
  BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);&lt;br /&gt;
  Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T(&amp;quot;ID_PANEL1&amp;quot;));&lt;br /&gt;
  BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);&lt;br /&gt;
  Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(400,300), wxFULL_REPAINT_ON_RESIZE, _T(//*)&lt;br /&gt;
&lt;br /&gt;
//***End of Part 1. Everything above this line was written by wxSmith *******&lt;br /&gt;
&lt;br /&gt;
//                                  Part 2. &lt;br /&gt;
&lt;br /&gt;
// Now comes the hand-coded section (with a few lines borrowed from wxSmith)&lt;br /&gt;
&lt;br /&gt;
    int nrows, ncols;&lt;br /&gt;
    nrows =20; ncols = 30;&lt;br /&gt;
&lt;br /&gt;
    Grid1-&amp;gt;CreateGrid(nrows,ncols); // wxSmith had Grid1-&amp;gt;CreateGrid(40.40);&lt;br /&gt;
    Grid1-&amp;gt;EnableEditing(true);     // from wxSmith&lt;br /&gt;
    Grid1-&amp;gt;EnableGridLines(true);   // from wxSmith&lt;br /&gt;
// Label some columns&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;)); //from wxSmith &lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));  //from wxSmith &lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(2, _(&amp;quot;gamma&amp;quot;)); //from wxSmith &lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(3, _(&amp;quot;delta &amp;quot;));&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(4, _(&amp;quot;epsilon&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Label some rows&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(0, _(&amp;quot;mu&amp;quot;)); // from wxSmith&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(1, _(&amp;quot;nu&amp;quot;)); // from wxSmith&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(2, _(&amp;quot;xi&amp;quot;)); // from wxSmith&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(3, _(&amp;quot;omicron&amp;quot;));&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(4, _(&amp;quot;pi&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Column or row labels can be set from C-strings whose&lt;br /&gt;
// values are determined at runtime by first converting&lt;br /&gt;
// the C-string to a wxString, as illustrated here:&lt;br /&gt;
&lt;br /&gt;
    char colone[10];        //colone is the variable C-string.&lt;br /&gt;
    strcpy(colone,&amp;quot;alpha2&amp;quot;);// Give it some content at run time.&lt;br /&gt;
    wxString ColumnName;    // Define a wxString which may be used repeatedly.&lt;br /&gt;
// Convert contents of the C-string to a wxString:&lt;br /&gt;
    ColumnName = wxString::FromUTF8(colone);&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0,ColumnName); // Set the column label.&lt;br /&gt;
&lt;br /&gt;
// Set some cell values&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 0, _(&amp;quot;2&amp;quot;)); //from wxSmith&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 1, _(&amp;quot;7&amp;quot;)); //from wxSmith&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 2, _(&amp;quot;6&amp;quot;)); //from wxSmith&lt;br /&gt;
&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Illustrate what SetColFormatFloat() does. From Smart &amp;amp; Hock, page 348 corrected.&lt;br /&gt;
	Grid1-&amp;gt;SetColFormatFloat(5,6,2); // Format numeric strings in column 5.&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0,5,_(&amp;quot;3.14159&amp;quot;)); // Put a number with 5 decimals there.&lt;br /&gt;
    // Put the same string in Column 4 for comparison.&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(0,4,_(&amp;quot;3.14159&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Here is how to show floats defined at run time in the wxGrid:&lt;br /&gt;
    float e = 2.71828;&lt;br /&gt;
    wxString cart;&lt;br /&gt;
    cart = wxString::Format(_T(&amp;quot;%f&amp;quot;), e);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1,4,cart);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1,5,cart);&lt;br /&gt;
&lt;br /&gt;
// Display a matrix of floats defined at run time.&lt;br /&gt;
    short i,j;&lt;br /&gt;
    float xx;&lt;br /&gt;
    for (i = 10; i &amp;lt;=12; i++){&lt;br /&gt;
        for (j = 10; j &amp;lt;= 12; j++){&lt;br /&gt;
            xx = i*j;&lt;br /&gt;
            xx = xx/2.;&lt;br /&gt;
            cart = wxString::Format(_T(&amp;quot;%8.2f&amp;quot;),xx);&lt;br /&gt;
            Grid1-&amp;gt;SetCellValue(i,j,cart);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
//&lt;br /&gt;
//                    *** Part 3 ***&lt;br /&gt;
// All that follows was written by wxSmith.&lt;br /&gt;
	Grid1-&amp;gt;SetDefaultCellFont( Grid1-&amp;gt;GetFont() );&lt;br /&gt;
	Grid1-&amp;gt;SetDefaultCellTextColour( Grid1-&amp;gt;GetForegroundColour() );&lt;br /&gt;
	BoxSizer2-&amp;gt;Add(Grid1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL| wxALIGN_CENTER_VERTICAL, 5);&lt;br /&gt;
	Panel1-&amp;gt;SetSizer(BoxSizer2);&lt;br /&gt;
	BoxSizer2-&amp;gt;Fit(Panel1);&lt;br /&gt;
	BoxSizer2-&amp;gt;SetSizeHints(Panel1);&lt;br /&gt;
	BoxSizer1-&amp;gt;Add(Panel1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);&lt;br /&gt;
	SetSizer(BoxSizer1);&lt;br /&gt;
	BoxSizer1-&amp;gt;Fit(this);&lt;br /&gt;
	BoxSizer1-&amp;gt;SetSizeHints(this);&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
wxSmith has separated its code into three parts – without, however, marking the divisions. I have added the division markers in the above listing. The first part has some preliminaries, the second part creates the grid and puts various values into it, and the third part attends to other matters whose precise function is elusive but presumably very necessary for the program to function properly. &lt;br /&gt;
&lt;br /&gt;
It is Part 2 that the programmer is likely to want to change. The first line of Part2 as written by wxSmith was: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The size of the grid may well not be known at compile time but depend on the matrix to be displayed. Somehow that variable size will be communicated to Barnum, perhaps by parameters in the call, perhaps by global variables, perhaps by a read from a file. To keep matters simple, I have represented that process by just defining nrows and ncols as ints in the code, but as far as the CreateGrid() function knows they came from somewhere else. So our Part2 begins:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    int nrows, ncols;&lt;br /&gt;
    nrows =20; ncols = 30;&lt;br /&gt;
    Grid1-&amp;gt;CreateGrid(nrows,ncols);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Just above these lines we need to mark the end of code that wxSmith controls. That end is marked by a  //*)  sign.  So this mark has been moved to precede these three lines. Part 1 of our code will therefore be everything down to and including this line.  The programmer should have no need to touch it save to allow Barnum to receive some variables from the program that calls it. &lt;br /&gt;
&lt;br /&gt;
We will use the same device for showing how to put floating point numbers known only at run time into the grid. We will define them as floats, and show how to put a float, no matter where it came from, into the grid. &lt;br /&gt;
&lt;br /&gt;
When it comes to displaying floating point numbers in the grid, however, we must deal with what appears to be an error in a couple of lines in the standard and most authoritative book on wxWidgets, ''Cross-Platform GUI Programming with wxWidgets'' by Smart and Hock. In the sole example given of a wxGrid, they write on page 348:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// We can specify that some cells will store numeric&lt;br /&gt;
// values rather than strings. Here we set grid column 5&lt;br /&gt;
// to hold floating point values displayed with width of 6&lt;br /&gt;
// and precision of 2&lt;br /&gt;
grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6, &amp;quot;3.1415&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This passage appears at least 18 times on the Internet without anyone observing that it is totally misleading if not dead wrong. To begin with, the last line is out of date and won't compile, at least not with Code::Blocks. It can be easily updated to:&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
But it does not illustrate the use of the SetColFormatFloat function. That command in the previous line applied to column 5 while this line puts a ''string'' – not a numeric value – into column 6, not 5. We can easily correct the column number:  &lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 5,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
But it is still putting a wxString – not a numeric value, and certainly not a float – into the cell.  It turns out that the assertion that “some cells will store numeric values rather than strings” is highly misleading at best. There is no elementary way to put anything other than a wxString into a cell of a wxGrid, nor to declare that a column will contain floats.  The function of SetColFormatFloat() is quite different. The command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is used to give a ''uniform appearance'' to the column. It makes all strings in column 5 representing numbers with decimal places appear with the same width and precision. Thus, after this command, the string “3.14159” in column 5 will appear as 3.14 and the string “3.1” will appear as 3.10.&lt;br /&gt;
&lt;br /&gt;
So then how do we show a floating point number in a wxGrid? We first have to convert it to a wxString and then put the string into the wxGrid. For example, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    float e = 2.71828; &lt;br /&gt;
    wxString cart; &lt;br /&gt;
    cart = wxString::Format(_T(&amp;quot;%f&amp;quot;), e);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart); &lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 5, cart); // To show what SetColFormatFloat does. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here ''cart'' is the wxString in which the numeric value of ''e'' rides into the grid. &lt;br /&gt;
Column or row labels can be set from C-strings whose values are determined at runtime by first converting the C-string to a wxString, as illustrated here:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    char colone[10];        //colone is the variable C-string.&lt;br /&gt;
    strcpy(colone,&amp;quot;alpha&amp;quot;);// Give it some content at run time.&lt;br /&gt;
    wxString ColumnName;    // Define a wxString which may be used repeatedly.&lt;br /&gt;
	 //Convert contents of the C-string to a wxString:&lt;br /&gt;
    ColumnName = wxString::FromUTF8(colone);&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0,ColumnName); // Set the column label.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When these lines have been added to Barnum and the code compiled and run, we get the result shown below.&lt;br /&gt;
&lt;br /&gt;
[[File : DiaGridFinal.png | |center|]]]&lt;br /&gt;
&lt;br /&gt;
Note that the floating point numbers appear with their full number of decimal places in column 4 (labeled &amp;quot;epsilon&amp;quot;)but in column 5 they have been rounded to 2 decimal places as a result of the SetColFormatFloat()  function.&lt;br /&gt;
&lt;br /&gt;
The last section of Part 2 shows how the wxString ''cart'' can be used over and over to carry numbers into the grid.&lt;br /&gt;
The result is show below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The result is shown below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
&lt;br /&gt;
[[File : xpy.png | |center]]&lt;br /&gt;
&lt;br /&gt;
As for the square of integers in the upper left corner of the grid, it is “magic”; all rows, columns and diagonals have the same sum. Anyone venturing into wxGrid land is going to need all the magic he can get. But studying Barnum.cpp or other wxSmith code should be helpful.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9264</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9264"/>
		<updated>2017-02-05T21:48:35Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and values numeric values in some elements of a 40x40 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The code written by wxSmith itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by variables in your program. The code wxSmith writes has the size of the grid given by two constants, the number of rows and the number of columns, but you can easily see from that code how to make the grid's size depend on variables in your code. &lt;br /&gt;
    &lt;br /&gt;
So let's get started. Create a new wxWidgets application. Call it DiaGrid and make it frame-based. We don't want the grid showing all the time, only when we call it up, so we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid for the program.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch. (This was discovered by a lot of trial and error.)&lt;br /&gt;
&lt;br /&gt;
Note that we did not put scroll bars on any of the components we used. The wxGrid component automatically carries its own scroll bars and any others just make for confusion.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog containing the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the letters of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for present purposes.&lt;br /&gt;
&lt;br /&gt;
Now we put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line. Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
&lt;br /&gt;
Let's now have a look at the code wxSmith has written for us. To avoid repetition, however, I will show the code after some additions by hand, but with clear markings distinguishing what wxSmith wrote from what was later added. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Barnum::Barnum(wxWindow* parent,wxWindowID id,const wxPoint&amp;amp; pos,const wxSize&amp;amp; size)&lt;br /&gt;
{&lt;br /&gt;
  //(*Initialize(Barnum)&lt;br /&gt;
  wxBoxSizer* BoxSizer2;&lt;br /&gt;
  wxBoxSizer* BoxSizer1;&lt;br /&gt;
  Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE |wxRESIZE_BORDER,  _T(&amp;quot;id&amp;quot;));&lt;br /&gt;
  SetClientSize(wxDefaultSize);&lt;br /&gt;
  Move(wxDefaultPosition);&lt;br /&gt;
  BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);&lt;br /&gt;
  Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T(&amp;quot;ID_PANEL1&amp;quot;));&lt;br /&gt;
  BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);&lt;br /&gt;
  Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(400,300), wxFULL_REPAINT_ON_RESIZE, _T(//*)&lt;br /&gt;
&lt;br /&gt;
//***End of Part 1. Everything above this line was written by wxSmith *******&lt;br /&gt;
&lt;br /&gt;
//                                  Part 2. &lt;br /&gt;
&lt;br /&gt;
// Now comes the hand-coded section (with a few lines borrowed from wxSmith)&lt;br /&gt;
&lt;br /&gt;
    int nrows, ncols;&lt;br /&gt;
    nrows =20; ncols = 30;&lt;br /&gt;
&lt;br /&gt;
    Grid1-&amp;gt;CreateGrid(nrows,ncols);&lt;br /&gt;
    Grid1-&amp;gt;EnableEditing(true);     // wxSmith loan&lt;br /&gt;
    Grid1-&amp;gt;EnableGridLines(true);   // wxSmith loan&lt;br /&gt;
// Label some columns&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;)); // wxSmith loan&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));  // wxSmith loan&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(2, _(&amp;quot;gamma&amp;quot;)); // wxSmith loan&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(3, _(&amp;quot;delta &amp;quot;));&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(4, _(&amp;quot;epsilon&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Label some rows&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(0, _(&amp;quot;mu&amp;quot;)); // wxSmith loan&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(1, _(&amp;quot;nu&amp;quot;)); // wxSmith loan&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(2, _(&amp;quot;xi&amp;quot;)); // wxSmith loan&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(3, _(&amp;quot;omicron&amp;quot;));&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(4, _(&amp;quot;pi&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Column or row labels can be set from C-strings whose&lt;br /&gt;
// values are determined at runtime by first converting&lt;br /&gt;
// the C-string to a wxString, as illustrated here:&lt;br /&gt;
&lt;br /&gt;
    char colone[10];        //colone is the variable C-string.&lt;br /&gt;
    strcpy(colone,&amp;quot;alpha2&amp;quot;);// Give it some content at run time.&lt;br /&gt;
    wxString ColumnName;    // Define a wxString which may be used repeatedly.&lt;br /&gt;
// Convert contents of the C-string to a wxString:&lt;br /&gt;
    ColumnName = wxString::FromUTF8(colone);&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0,ColumnName); // Set the column label.&lt;br /&gt;
&lt;br /&gt;
// Set some cell values&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 0, _(&amp;quot;2&amp;quot;)); // wxSmith loan&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 1, _(&amp;quot;7&amp;quot;)); // wxSmith loan&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 2, _(&amp;quot;6&amp;quot;)); // wxSmith loan&lt;br /&gt;
&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Illustrate what SetColFormatFloat() does. From Smart &amp;amp; Hock, page 348 corrected.&lt;br /&gt;
	Grid1-&amp;gt;SetColFormatFloat(5,6,2); // Format numeric strings in column 5.&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0,5,_(&amp;quot;3.14159&amp;quot;)); // Put a number with 5 decimals there.&lt;br /&gt;
    // Put the same string in Column 4 for comparison.&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(0,4,_(&amp;quot;3.14159&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// How to show floats defined at run time in the wxGrid:&lt;br /&gt;
    float e = 2.71828;&lt;br /&gt;
    wxString cart;&lt;br /&gt;
    cart = wxString::Format(_T(&amp;quot;%f&amp;quot;), e);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1,4,cart);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1,5,cart);&lt;br /&gt;
&lt;br /&gt;
// Display a matrix of floats defined at run time.&lt;br /&gt;
    short i,j;&lt;br /&gt;
    float xx;&lt;br /&gt;
    for (i = 10; i &amp;lt;=12; i++){&lt;br /&gt;
        for (j = 10; j &amp;lt;= 12; j++){&lt;br /&gt;
            xx = i*j;&lt;br /&gt;
            xx = xx/2.;&lt;br /&gt;
            cart = wxString::Format(_T(&amp;quot;%8.2f&amp;quot;),xx);&lt;br /&gt;
            Grid1-&amp;gt;SetCellValue(i,j,cart);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
//&lt;br /&gt;
//                    *** Part 3 ***&lt;br /&gt;
// All that follows was written by wxSmith.&lt;br /&gt;
	Grid1-&amp;gt;SetDefaultCellFont( Grid1-&amp;gt;GetFont() );&lt;br /&gt;
	Grid1-&amp;gt;SetDefaultCellTextColour( Grid1-&amp;gt;GetForegroundColour() );&lt;br /&gt;
	BoxSizer2-&amp;gt;Add(Grid1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL| wxALIGN_CENTER_VERTICAL, 5);&lt;br /&gt;
	Panel1-&amp;gt;SetSizer(BoxSizer2);&lt;br /&gt;
	BoxSizer2-&amp;gt;Fit(Panel1);&lt;br /&gt;
	BoxSizer2-&amp;gt;SetSizeHints(Panel1);&lt;br /&gt;
	BoxSizer1-&amp;gt;Add(Panel1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);&lt;br /&gt;
	SetSizer(BoxSizer1);&lt;br /&gt;
	BoxSizer1-&amp;gt;Fit(this);&lt;br /&gt;
	BoxSizer1-&amp;gt;SetSizeHints(this);&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
wxSmith has separated its code into three parts – without, however, marking the divisions. I have added the division markers in the above listing. The first part has some preliminaries, the second part creates the grid and puts various values into it, and the third part attends to other matters whose precise function is elusive but presumably very necessary for the program to function properly. &lt;br /&gt;
&lt;br /&gt;
It is Part 2 that the programmer is likely to want to change. The first line of Part2 as written by wxSmith was: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The size of the grid may well not be known at compile time but depend on the matrix to be displayed. Somehow that variable size will be communicated to Barnum, perhaps by parameters in the call, perhaps by global variables, perhaps by a read from a file. To keep matters simple, I have represented that process by just defining nrows and ncols as shorts in the code, but as far as the CreateGrid() function knows they came from somewhere else. So our Part2 begins:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    int nrows, ncols;&lt;br /&gt;
    nrows =20; ncols = 30;&lt;br /&gt;
    Grid1-&amp;gt;CreateGrid(nrows,ncols);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Just above these lines we need to mark the end of code that wxSmith controls. That end is marked by a  //*)  sign.  So this mark has been moved to precede these three lines. Part 1 of our code will therefore be everything down to and including this line.  The programmer should have no need to touch it save to allow Barnum to receive some variables from the program that calls it. &lt;br /&gt;
&lt;br /&gt;
We will use the same device for showing how to put floating point numbers known only at run time into the grid. We will define them as floats, and show how to put a float, no matter where it came from, into the grid. &lt;br /&gt;
&lt;br /&gt;
When it comes to displaying floating point numbers in the grid, however, we must deal with what appears to be an error in a couple of lines in the standard and most authoritative book on wxWidgets, ''Cross-Platform GUI Programming with wxWidgets'' by Smart and Hock. In the sole example given of a wxGrid, they write on page 348:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// We can specify that some cells will store numeric&lt;br /&gt;
// values rather than strings. Here we set grid column 5&lt;br /&gt;
// to hold floating point values displayed with width of 6&lt;br /&gt;
// and precision of 2&lt;br /&gt;
grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6, &amp;quot;3.1415&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This passage appears at least 18 times on the Internet without anyone observing that it is totally misleading if not dead wrong. To begin with, the last line is out of date and won't compile, at least not with Code::Blocks. It can be easily updated to:&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
But it does not illustrate the use of the SetColFormatFloat function. That command in the previous line applied to column 5 while this line puts a ''string'' – not a numeric value – into column 6, not 5. We can easily correct the column:  &lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 5,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
But it is still putting a wxString – not a numeric value, and certainly not a float – into the cell.  It turns out that the assertion that “some cells will store numeric values rather than strings” is highly misleading at best. There is no elementary way to put anything other than a wxString into a cell of a wxGrid, nor to declare that a column will contain floats.  The function of SetColFormatFloat() is quite different. The command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is used to give a ''uniform appearance'' to the column. It makes all strings in column 5 representing numbers with decimal places appear with the same width and precision. Thus, after this command, the string “3.14159” in column 5 will appear as 3.14 and the string “3.1” will appear as 3.10.&lt;br /&gt;
&lt;br /&gt;
So then how do we show a floating point number in a wxGrid? We first have to convert it to a wxString and then put the string into the wxGrid. For example, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    float e = 2.71828; &lt;br /&gt;
    wxString cart; &lt;br /&gt;
    cart = wxString::Format(_T(&amp;quot;%f&amp;quot;), e);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart); &lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 5, cart); // To show what SetColFormatFloat does. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here ''cart'' is the wxString in which the numeric value of ''e'' rides into the grid. &lt;br /&gt;
Column or row labels can be set from C-strings whose values are determined at runtime by first converting the C-string to a wxString, as illustrated here:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    char colone[10];        //colone is the variable C-string.&lt;br /&gt;
    strcpy(colone,&amp;quot;alpha&amp;quot;);// Give it some content at run time.&lt;br /&gt;
    wxString ColumnName;    // Define a wxString which may be used repeatedly.&lt;br /&gt;
	 //Convert contents of the C-string to a wxString:&lt;br /&gt;
    ColumnName = wxString::FromUTF8(colone);&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0,ColumnName); // Set the column label.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When these lines have been added to Barnum and the code compiled and run, we get the result shown below.&lt;br /&gt;
&lt;br /&gt;
[[File : DiaGridFinal.png | |center|]]]&lt;br /&gt;
&lt;br /&gt;
Note that the floating point numbers appear with their full number of decimal places in column 4 (labeled &amp;quot;epsilon&amp;quot;)but in column 5 they have been rounded to 2 decimal places as a result of the SetColFormatFloat()  function.&lt;br /&gt;
&lt;br /&gt;
The last section of Part 2 shows how the wxString ''cart'' can be used over and over to carry numbers into the grid.&lt;br /&gt;
The result is show below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The result is shown below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
&lt;br /&gt;
[[File : xpy.png | |center]]&lt;br /&gt;
&lt;br /&gt;
As for the square of integers in the upper left corner of the grid, it is “magic”; all rows, columns and diagonals have the same sum. Anyone venturing into wxGrid land is going to need all the magic he can get. But studying Barnum.cpp or other wxSmith code should be helpful.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=File:DiaGridFinal.png&amp;diff=9263</id>
		<title>File:DiaGridFinal.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=File:DiaGridFinal.png&amp;diff=9263"/>
		<updated>2017-02-05T21:32:48Z</updated>

		<summary type="html">&lt;p&gt;Grouch: Final file for Tutorial 10.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Final file for Tutorial 10.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9262</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9262"/>
		<updated>2017-02-05T20:32:34Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and values numeric values in some elements of a 40x40 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The code written by wxSmith itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by variables in your program. The code wxSmith writes has the size of the grid given by two constants, the number of rows and the number of columns, but you can easily see from that code how to make the grid's size depend on variables in your code. &lt;br /&gt;
    &lt;br /&gt;
So let's get started. Create a new wxWidgets application. Call it DiaGrid and make it frame-based. We don't want the grid showing all the time, only when we call it up, so we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid for the program.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch. (This was discovered by a lot of trial and error.)&lt;br /&gt;
&lt;br /&gt;
Note that we did not put scroll bars on any of the components we used. The wxGrid component automatically carries its own scroll bars and any others just make for confusion.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog containing the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the letters of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for present purposes.&lt;br /&gt;
&lt;br /&gt;
Now we put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line. Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
&lt;br /&gt;
Let's now have a look at the code wxSmith has written for us. To avoid repetition, however, I will show the code after some additions by hand, but with clear markings distinguishing what wxSmith wrote from what was later added. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Barnum::Barnum(wxWindow* parent,wxWindowID id,const wxPoint&amp;amp; pos,const wxSize&amp;amp; size)&lt;br /&gt;
{&lt;br /&gt;
  //(*Initialize(Barnum)&lt;br /&gt;
  wxBoxSizer* BoxSizer2;&lt;br /&gt;
  wxBoxSizer* BoxSizer1;&lt;br /&gt;
  Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE |wxRESIZE_BORDER,  _T(&amp;quot;id&amp;quot;));&lt;br /&gt;
  SetClientSize(wxDefaultSize);&lt;br /&gt;
  Move(wxDefaultPosition);&lt;br /&gt;
  BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);&lt;br /&gt;
  Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T(&amp;quot;ID_PANEL1&amp;quot;));&lt;br /&gt;
  BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);&lt;br /&gt;
  Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(400,300), wxFULL_REPAINT_ON_RESIZE, _T(//*)&lt;br /&gt;
&lt;br /&gt;
//***End of Part 1. Everything above this line was written by wxSmith *******&lt;br /&gt;
&lt;br /&gt;
//                                  Part 2. &lt;br /&gt;
&lt;br /&gt;
// Now comes the hand-coded section (with a few lines borrowed from wxSmith)&lt;br /&gt;
&lt;br /&gt;
    int nrows, ncols;&lt;br /&gt;
    nrows =20; ncols = 30;&lt;br /&gt;
&lt;br /&gt;
    Grid1-&amp;gt;CreateGrid(nrows,ncols);&lt;br /&gt;
    Grid1-&amp;gt;EnableEditing(true);     // wxSmith loan&lt;br /&gt;
    Grid1-&amp;gt;EnableGridLines(true);   // wxSmith loan&lt;br /&gt;
// Label some columns&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;)); // wxSmith loan&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));  // wxSmith loan&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(2, _(&amp;quot;gamma&amp;quot;)); // wxSmith loan&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(3, _(&amp;quot;delta &amp;quot;));&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(4, _(&amp;quot;epsilon&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Label some rows&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(0, _(&amp;quot;mu&amp;quot;)); // wxSmith loan&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(1, _(&amp;quot;nu&amp;quot;)); // wxSmith loan&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(2, _(&amp;quot;xi&amp;quot;)); // wxSmith loan&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(3, _(&amp;quot;omicron&amp;quot;));&lt;br /&gt;
   Grid1-&amp;gt;SetRowLabelValue(4, _(&amp;quot;pi&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Column or row labels can be set from C-strings whose&lt;br /&gt;
// values are determined at runtime by first converting&lt;br /&gt;
// the C-string to a wxString, as illustrated here:&lt;br /&gt;
&lt;br /&gt;
    char colone[10];        //colone is the variable C-string.&lt;br /&gt;
    strcpy(colone,&amp;quot;alpha2&amp;quot;);// Give it some content at run time.&lt;br /&gt;
    wxString ColumnName;    // Define a wxString which may be used repeatedly.&lt;br /&gt;
// Convert contents of the C-string to a wxString:&lt;br /&gt;
    ColumnName = wxString::FromUTF8(colone);&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0,ColumnName); // Set the column label.&lt;br /&gt;
&lt;br /&gt;
// Set some cell values&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 0, _(&amp;quot;2&amp;quot;)); // wxSmith loan&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 1, _(&amp;quot;7&amp;quot;)); // wxSmith loan&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 2, _(&amp;quot;6&amp;quot;)); // wxSmith loan&lt;br /&gt;
&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Illustrate what SetColFormatFloat() does. From Smart &amp;amp; Hock, page 348 corrected.&lt;br /&gt;
	Grid1-&amp;gt;SetColFormatFloat(5,6,2); // Format numeric strings in column 5.&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0,5,_(&amp;quot;3.14159&amp;quot;)); // Put a number with 5 decimals there.&lt;br /&gt;
    // Put the same string in Column 4 for comparison.&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(0,4,_(&amp;quot;3.14159&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// How to show floats defined at run time in the wxGrid:&lt;br /&gt;
    float e = 2.71828;&lt;br /&gt;
    wxString cart;&lt;br /&gt;
    cart = wxString::Format(_T(&amp;quot;%f&amp;quot;), e);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1,4,cart);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1,5,cart);&lt;br /&gt;
&lt;br /&gt;
// Display a matrix of floats defined at run time.&lt;br /&gt;
    short i,j;&lt;br /&gt;
    float xx;&lt;br /&gt;
    for (i = 10; i &amp;lt;=12; i++){&lt;br /&gt;
        for (j = 10; j &amp;lt;= 12; j++){&lt;br /&gt;
            xx = i*j;&lt;br /&gt;
            xx = xx/2.;&lt;br /&gt;
            cart = wxString::Format(_T(&amp;quot;%8.2f&amp;quot;),xx);&lt;br /&gt;
            Grid1-&amp;gt;SetCellValue(i,j,cart);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
//&lt;br /&gt;
//                    *** Part 3 ***&lt;br /&gt;
// All that follows was written by wxSmith.&lt;br /&gt;
	Grid1-&amp;gt;SetDefaultCellFont( Grid1-&amp;gt;GetFont() );&lt;br /&gt;
	Grid1-&amp;gt;SetDefaultCellTextColour( Grid1-&amp;gt;GetForegroundColour() );&lt;br /&gt;
	BoxSizer2-&amp;gt;Add(Grid1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL| wxALIGN_CENTER_VERTICAL, 5);&lt;br /&gt;
	Panel1-&amp;gt;SetSizer(BoxSizer2);&lt;br /&gt;
	BoxSizer2-&amp;gt;Fit(Panel1);&lt;br /&gt;
	BoxSizer2-&amp;gt;SetSizeHints(Panel1);&lt;br /&gt;
	BoxSizer1-&amp;gt;Add(Panel1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);&lt;br /&gt;
	SetSizer(BoxSizer1);&lt;br /&gt;
	BoxSizer1-&amp;gt;Fit(this);&lt;br /&gt;
	BoxSizer1-&amp;gt;SetSizeHints(this);&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
wxSmith has separated its code into three parts – without, however, marking the divisions. I have added the division markers in the above listing. The first part has some preliminaries, the second part creates the grid and puts various values into it, and the third part attends to other matters whose precise function is elusive but presumably very necessary for the program to function properly. &lt;br /&gt;
It is Part 2 that the programmer is likely to want to change. The first line of Part2 as written by wxSmith was: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The size of the grid may well not be known at compile time but depend on the matrix to be displayed. Somehow that variable size will be communicated to Barnum, perhaps by parameters in the call, perhaps by global variables, perhaps by a read from a file. To keep matters simple, I have represented that process by just defining nrows and ncols as shorts in the code, but as far as the CreateGrid() function knows they came from somewhere else. So our Part2 begins:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    int nrows, ncols;&lt;br /&gt;
    nrows =20; ncols = 30;&lt;br /&gt;
    Grid1-&amp;gt;CreateGrid(nrows,ncols);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Just above these lines we need to mark the end of code that wxSmith controls. That end is marked by a  //*)  sign.  So this mark has been moved to precede these three lines. Part 1 of our code will therefore be everything down to and including this line.  The programmer should have no need to touch it save to allow Barnum to receive some variables from the program that calls it. &lt;br /&gt;
&lt;br /&gt;
We will use the same device for showing how to put floating point numbers known only at run time into the grid. We will define them as floats, and show how to put a float, no matter where it came from, into the grid. &lt;br /&gt;
&lt;br /&gt;
When it comes to displaying floating point numbers in the grid, however, we must deal with what appears to be an error in a couple of lines in the standard and most authoritative book on wxWidgets, ''Cross-Platform GUI Programming with wxWidgets'' by Smart and Hock. In the sole example given of a wxGrid, they write on page 348:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// We can specify that some cells will store numeric&lt;br /&gt;
// values rather than strings. Here we set grid column 5&lt;br /&gt;
// to hold floating point values displayed with width of 6&lt;br /&gt;
// and precision of 2&lt;br /&gt;
grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6, &amp;quot;3.1415&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This passage appears at least 18 times on the Internet without anyone observing that it is totally misleading if not dead wrong. To begin with, the last line is out of date and won't compile, at least not with Code::Blocks. It can be easily updated to:&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
But it does not illustrate the use of the SetColFormatFloat function. That command in the previous line applied to column 5 while this line puts a ''string'' – not a numeric value – into column 6, not 5. We can easily correct the column:  &lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 5,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
But it is still putting a wxString – not a numeric value, and certainly not a float – into the cell.  It turns out that the assertion that “some cells will store numeric values rather than strings” is highly questionable at best. There is no elementary way to put anything other than a wxString into a cell of a wxGrid, nor to declare that a column will contain floats.  The function of SetColFormatFloat() is quite different. The command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is used to give a ''uniform appearance'' to the column. It makes all strings in column 5 representing numbers with decimal places appear with the same width and precision. Thus, after this command, the string “3.14159” in column 5 will appear as 3.14 and the string “3.1” will appear as 3.10.&lt;br /&gt;
&lt;br /&gt;
So then how do we show a floating point number in a wxGrid? We first have to convert it to a wxString and then put the string into the wxGrid. For example, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    float e = 2.71828; &lt;br /&gt;
    wxString cart; &lt;br /&gt;
    cart = wxString::Format(_T(&amp;quot;%f&amp;quot;), e);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart); &lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 5, cart); // To show what SetColFormatFloat does. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here ''cart'' is the wxString in which the numeric value of ''e'' rides into the grid. &lt;br /&gt;
Column or row labels can be set from C-strings whose values are determined at runtime by first converting the C-string to a wxString, as illustrated here:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    char colone[10];        //colone is the variable C-string.&lt;br /&gt;
    strcpy(colone,&amp;quot;alpha&amp;quot;);// Give it some content at run time.&lt;br /&gt;
    wxString ColumnName;    // Define a wxString which may be used repeatedly.&lt;br /&gt;
	 //Convert contents of the C-string to a wxString:&lt;br /&gt;
    ColumnName = wxString::FromUTF8(colone);&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0,ColumnName); // Set the column label.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When these lines have been added to Barnum and the code compiled and run, we get the result shown below. Note that the floating point numbers appear with their full number of decimal places in column 4, but in column 5 they have been rounded to 2 decimal places as a result of the SetColFormatFloat()  functions.&lt;br /&gt;
The wxString ''cart'' can be used over and over to carry numbers into the grid, as we illustrate here: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    short i,j;&lt;br /&gt;
    float xx;&lt;br /&gt;
&lt;br /&gt;
    for (i = 10; i &amp;lt;=12; i++){&lt;br /&gt;
        for (j = 10; j &amp;lt;= 12; j++){&lt;br /&gt;
            xx = i*j;&lt;br /&gt;
            xx = xx/2.;&lt;br /&gt;
            cart = wxString::Format(_T(&amp;quot;%8.2f&amp;quot;),xx);&lt;br /&gt;
            Grid1-&amp;gt;SetCellValue(i,j,cart);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result is show below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
[[File : Squarepie.png  | |center|]]&lt;br /&gt;
&lt;br /&gt;
The wxString ''cart'' defined above can now be used over and over to carry numbers into the grid, as we illustrate here: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    short i,j;&lt;br /&gt;
    float xx;&lt;br /&gt;
&lt;br /&gt;
    for (i = 10; i &amp;lt;=12; i++){&lt;br /&gt;
        for (j = 10; j &amp;lt;= 12; j++){&lt;br /&gt;
            xx = i*j;&lt;br /&gt;
            xx = xx/2.;&lt;br /&gt;
            cart = wxString::Format(_T(&amp;quot;%8.2f&amp;quot;),xx);&lt;br /&gt;
            Grid1-&amp;gt;SetCellValue(i,j,cart);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result is shown below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
&lt;br /&gt;
[[File : xpy.png | |center]]&lt;br /&gt;
&lt;br /&gt;
As for the square of integers in the upper left corner of the grid, it is “magic”; all rows, columns and diagonals have the same sum. Anyone venturing into wxGrid land is going to need all the magic he can get. But studying Barnum.cpp or other wxSmith code should be helpful.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9261</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9261"/>
		<updated>2017-02-05T19:42:57Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and values numeric values in some elements of a 40x40 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The code written by wxSmith itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by variables in your program. The code wxSmith writes has the size of the grid given by two constants, the number of rows and the number of columns, but you can easily see from that code how to make the grid's size depend on variables in your code. &lt;br /&gt;
    &lt;br /&gt;
So let's get started. Create a new wxWidgets application. Call it DiaGrid and make it frame-based. We don't want the grid showing all the time, only when we call it up, so we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid for the program.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch. (This was discovered by a lot of trial and error.)&lt;br /&gt;
&lt;br /&gt;
Note that we did not put scroll bars on any of the components we used. The wxGrid component automatically carries its own scroll bars and any others just make for confusion.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog containing the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the letters of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for present purposes.&lt;br /&gt;
&lt;br /&gt;
Now we put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line. Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
&lt;br /&gt;
Let's now have a look at the code wxSmith has written for us. To avoid repetition, however, I will show the code after some additions by hand, but with clear marking of what wxSmith wrote from what was later added. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Barnum::Barnum(wxWindow* parent,wxWindowID id,const wxPoint&amp;amp; pos,const wxSize&amp;amp; size)&lt;br /&gt;
{&lt;br /&gt;
  //(*Initialize(Barnum)&lt;br /&gt;
  wxBoxSizer* BoxSizer2;&lt;br /&gt;
  wxBoxSizer* BoxSizer1;&lt;br /&gt;
  Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER,  _T(&amp;quot;id&amp;quot;));&lt;br /&gt;
  SetClientSize(wxDefaultSize);&lt;br /&gt;
  Move(wxDefaultPosition);&lt;br /&gt;
  BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);&lt;br /&gt;
  Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T(&amp;quot;ID_PANEL1&amp;quot;));&lt;br /&gt;
  BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);&lt;br /&gt;
Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(400,300), wxFULL_REPAINT_ON_RESIZE, _T(//*)&lt;br /&gt;
&lt;br /&gt;
//***End of Part 1. Everything above this line was written by wxSmith *******&lt;br /&gt;
&lt;br /&gt;
//                                  Part 2. &lt;br /&gt;
&lt;br /&gt;
// Now comes the hand-coded section (with a few lines borrowed from wxSmith)&lt;br /&gt;
&lt;br /&gt;
    int nrows, ncols;&lt;br /&gt;
    nrows =20; ncols = 30;&lt;br /&gt;
&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(nrows,ncols);&lt;br /&gt;
	Grid1-&amp;gt;EnableEditing(true);     // wxSmith loan&lt;br /&gt;
	Grid1-&amp;gt;EnableGridLines(true);   // wxSmith loan&lt;br /&gt;
	// Label some columns&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;)); // wxSmith loan&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));  // wxSmith loan&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(2, _(&amp;quot;gamma&amp;quot;)); // wxSmith loan&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(3, _(&amp;quot;delta &amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(4, _(&amp;quot;epsilon&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
	// Label some rows&lt;br /&gt;
	Grid1-&amp;gt;SetRowLabelValue(0, _(&amp;quot;mu&amp;quot;)); // wxSmith loan&lt;br /&gt;
	Grid1-&amp;gt;SetRowLabelValue(1, _(&amp;quot;nu&amp;quot;)); // wxSmith loan&lt;br /&gt;
	Grid1-&amp;gt;SetRowLabelValue(2, _(&amp;quot;xi&amp;quot;)); // wxSmith loan&lt;br /&gt;
	Grid1-&amp;gt;SetRowLabelValue(3, _(&amp;quot;omicron&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetRowLabelValue(4, _(&amp;quot;pi&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Column or row labels can be set from C-strings whose&lt;br /&gt;
// values are determined at runtime by first converting&lt;br /&gt;
// the C-string to a wxString, as illustrated here:&lt;br /&gt;
&lt;br /&gt;
    char colone[10];        //colone is the variable C-string.&lt;br /&gt;
    strcpy(colone,&amp;quot;alpha2&amp;quot;);// Give it some content at run time.&lt;br /&gt;
    wxString ColumnName;    // Define a wxString which may be used repeatedly.&lt;br /&gt;
	 //Convert contents of the C-string to a wxString:&lt;br /&gt;
    ColumnName = wxString::FromUTF8(colone);&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0,ColumnName); // Set the column label.&lt;br /&gt;
&lt;br /&gt;
// Set some cell values&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 0, _(&amp;quot;2&amp;quot;)); // wxSmith loan&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 1, _(&amp;quot;7&amp;quot;)); // wxSmith loan&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 2, _(&amp;quot;6&amp;quot;)); // wxSmith loan&lt;br /&gt;
&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// Illustrate what SetColFormatFloat() does. From Smart &amp;amp; Hock, page 348 corrected.&lt;br /&gt;
	Grid1-&amp;gt;SetColFormatFloat(5,6,2); // Format numeric strings in column 5.&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0,5,_(&amp;quot;3.14159&amp;quot;)); // Put a number with 5 decimals there.&lt;br /&gt;
    // Put the same string in Column 4 for comoparison.&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(0,4,_(&amp;quot;3.14159&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
// How to show floats defined at run time in the wxGrid:&lt;br /&gt;
    float e = 2.71828;&lt;br /&gt;
    wxString cart;&lt;br /&gt;
    cart = wxString::Format(_T(&amp;quot;%f&amp;quot;), e);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1,5,cart);&lt;br /&gt;
&lt;br /&gt;
// Display a matrix of floats defined at run time.&lt;br /&gt;
    short i,j;&lt;br /&gt;
    float xx;&lt;br /&gt;
    for (i = 10; i &amp;lt;=12; i++){&lt;br /&gt;
        for (j = 10; j &amp;lt;= 12; j++){&lt;br /&gt;
            xx = i*j;&lt;br /&gt;
            xx = xx/2.;&lt;br /&gt;
            cart = wxString::Format(_T(&amp;quot;%8.2f&amp;quot;),xx);&lt;br /&gt;
            Grid1-&amp;gt;SetCellValue(i,j,cart);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
//&lt;br /&gt;
//                    *** Part 3 ***&lt;br /&gt;
// All that follows was written by wxSmith.&lt;br /&gt;
	Grid1-&amp;gt;SetDefaultCellFont( Grid1-&amp;gt;GetFont() );&lt;br /&gt;
	Grid1-&amp;gt;SetDefaultCellTextColour( Grid1-&amp;gt;GetForegroundColour() );&lt;br /&gt;
	BoxSizer2-&amp;gt;Add(Grid1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|		  	            	     wxALIGN_CENTER_VERTICAL, 5);&lt;br /&gt;
	Panel1-&amp;gt;SetSizer(BoxSizer2);&lt;br /&gt;
	BoxSizer2-&amp;gt;Fit(Panel1);&lt;br /&gt;
	BoxSizer2-&amp;gt;SetSizeHints(Panel1);&lt;br /&gt;
	BoxSizer1-&amp;gt;Add(Panel1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|				     wxALIGN_CENTER_VERTICAL, 5);&lt;br /&gt;
	SetSizer(BoxSizer1);&lt;br /&gt;
	BoxSizer1-&amp;gt;Fit(this);&lt;br /&gt;
	BoxSizer1-&amp;gt;SetSizeHints(this);&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
wxSmith has separated its code into three parts – without, however, marking the divisions. I have added the division markers in the above listing. The first part has some preliminaries, the second part creates the grid and puts various values into it, and the third part attends to other matters whose precise function is elusive but  presumably very necessary for the program to function properly. &lt;br /&gt;
It is Part 2 that the programmer is likely to want to change. The first line of Part2 as written by wxSmith was: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The size of the grid may well not be known at compile time but depend on the matrix to be displayed. Somehow that variable size will be communicated to Barnum, perhaps by parameters in the call, perhaps by global variables, perhaps by a read from a file. To keep matters simple, we will represent that process by just defining nrows and ncols in the code, but as far as the GreateGrid() function knows they came from somewhere else. So our Part2 begins:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    int nrows, ncols;&lt;br /&gt;
    nrows =20; ncols = 30;&lt;br /&gt;
    Grid1-&amp;gt;CreateGrid(nrows,ncols);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Just above these lines we need to mark the end of code that wxSmith controls. That end is marked by a  //*)  sign.  So this mark has been moved to precede these three lines. Part 1 of our code will therefore be everything down to and including this line.  The programmer should have no need to touch it save to allow Barnum to receive some variables from the program that calls it. &lt;br /&gt;
&lt;br /&gt;
We will use the same device for showing how to put floating point numbers known only at run time into the grid. We will define them as floats, and show how to get a float, no matter where it came from, into the grid. &lt;br /&gt;
When it comes to displaying floating point numbers in the grid, however.  we must deal with what appears to be an error in a couple of lines in the standard and most authoritative book on wxWidgets, ''Cross-Platform GUI Programming with wxWidgets'' by Smart and Hock. In the sole example given of a wxGrid, they write on page 348:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// We can specify that some cells will store numeric&lt;br /&gt;
// values rather than strings. Here we set grid column 5&lt;br /&gt;
// to hold floating point values displayed with width of 6&lt;br /&gt;
// and precision of 2&lt;br /&gt;
grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6, &amp;quot;3.1415&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This passage appears at least 18 times on the Internet without anyone observing that it is totally misleading if not dead wrong. To begin with, the last line is out of date and won't compile, at least not with Code::Blocks. It can be easily updated to:&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
But it does not illustrate the use of the SetColFormatFloat function. That command in the previous line applied to column 5 while this line puts a ''string'' – not a numeric value – into column 6, not 5. We can easily correct the column:  &lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 5,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
But it is still putting a wxString – not a numeric value, and certainly not a float – into the cell.  It turns out that the assertion that “some cells will store numeric values rather than strings” is highly questionable at best. There is no elementary way to put anything other than a wxString into a cell of a wxGrid, nor to declare that a column will contain floats.  The function of SetColFormatFloat() is quite different. The command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is used to give a ''uniform appearance'' to the column. It makes all strings in column 5 representing numbers with decimal places appear with the same width and precision. Thus, after this command, the string “3.14159” in column 5 will appear as 3.14 and the string “3.1” will appear as 3.10.&lt;br /&gt;
&lt;br /&gt;
So then how do we show a floating point number in a wxGrid? We first have to convert it to a wxString and then put the string into the wxGrid. For example, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    float e = 2.71828; &lt;br /&gt;
    wxString cart; &lt;br /&gt;
    cart = wxString::Format(_T(&amp;quot;%f&amp;quot;), e);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart); &lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 5, cart); // To show what SetColFormatFloat does. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here ''cart'' is the wxString in which the numeric value of ''e'' rides into the grid. &lt;br /&gt;
Column or row labels can be set from C-strings whose values are determined at runtime by first converting the C-string to a wxString, as illustrated here:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    char colone[10];        //colone is the variable C-string.&lt;br /&gt;
    strcpy(colone,&amp;quot;alpha&amp;quot;);// Give it some content at run time.&lt;br /&gt;
    wxString ColumnName;    // Define a wxString which may be used repeatedly.&lt;br /&gt;
	 //Convert contents of the C-string to a wxString:&lt;br /&gt;
    ColumnName = wxString::FromUTF8(colone);&lt;br /&gt;
    Grid1-&amp;gt;SetColLabelValue(0,ColumnName); // Set the column label.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When these lines have been added to Barnum and the code compiled and run, we get the result shown below. Note that the floating point numbers appear with their full number of decimal places in column 4, but in column 5 they have been rounded to 2 decimal places as a result of the SetColFormatFloat()  functions.&lt;br /&gt;
The wxString ''cart'' can be used over and over to carry numbers into the grid, as we illustrate here: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    short i,j;&lt;br /&gt;
    float xx;&lt;br /&gt;
&lt;br /&gt;
    for (i = 10; i &amp;lt;=12; i++){&lt;br /&gt;
        for (j = 10; j &amp;lt;= 12; j++){&lt;br /&gt;
            xx = i*j;&lt;br /&gt;
            xx = xx/2.;&lt;br /&gt;
            cart = wxString::Format(_T(&amp;quot;%8.2f&amp;quot;),xx);&lt;br /&gt;
            Grid1-&amp;gt;SetCellValue(i,j,cart);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result is show below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
[[File : Squarepie.png  | |center|]]&lt;br /&gt;
&lt;br /&gt;
The wxString ''cart'' defined above can now be used over and over to carry numbers into the grid, as we illustrate here: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    short i,j;&lt;br /&gt;
    float xx;&lt;br /&gt;
&lt;br /&gt;
    for (i = 10; i &amp;lt;=12; i++){&lt;br /&gt;
        for (j = 10; j &amp;lt;= 12; j++){&lt;br /&gt;
            xx = i*j;&lt;br /&gt;
            xx = xx/2.;&lt;br /&gt;
            cart = wxString::Format(_T(&amp;quot;%8.2f&amp;quot;),xx);&lt;br /&gt;
            Grid1-&amp;gt;SetCellValue(i,j,cart);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result is shown below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
&lt;br /&gt;
[[File : xpy.png | |center]]&lt;br /&gt;
&lt;br /&gt;
As for the square of integers in the upper left corner of the grid, it is “magic”; all rows, columns and diagonals have the same sum. Anyone venturing into wxGrid land is going to need all the magic he can get. But studying Barnum.cpp or other wxSmith code should be helpful.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9245</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9245"/>
		<updated>2017-01-28T19:56:12Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and values numeric values in some elements of a 40x40 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The code written by wxSmith itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by variables in your program. The code wxSmith writes has the size of the grid given by two constants, the number of rows and the number of columns, but you can easily see from that code how to make the grid's size depend on variables in your code. &lt;br /&gt;
    &lt;br /&gt;
So let's get started. Create a new wxWidgets application. Call it DiaGrid and make it frame-based. We don't want the grid showing all the time, only when we call it up, so we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid for the program.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch. (This was discovered by a lot of trial and error.)&lt;br /&gt;
&lt;br /&gt;
Note that we did not put scroll bars on any of the components we used. The wxGrid component automatically carries its own scroll bars and any others just make for confusion.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog containing the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the letters of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for present purposes.&lt;br /&gt;
&lt;br /&gt;
Now we put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line. Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
&lt;br /&gt;
Now let us have a look at the code wxSmith has written for us. It is in Barnum.cpp.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(300,200), 		&lt;br /&gt;
              wxFULL_REPAINT_ON_RESIZE, _T(&amp;quot;ID_GRID1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
	Grid1-&amp;gt;EnableEditing(false);&lt;br /&gt;
	Grid1-&amp;gt;EnableGridLines(true);&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We see immediately that wxSmith starts the row and column numbering from 0. Note how it set the values of the three elements in the 0th row with a call to SetCellValue(). The first two arguments in this call are the row and column number; the third must be a wxString – not a standard C string but a wxString. The _(&amp;quot; … &amp;quot;) structure converts what is inside the quotation marks to a wxString. &lt;br /&gt;
&lt;br /&gt;
Let's now add more data to our array with lines below the //*) which marks the end of the code wxSmith regards as its property. First we will fill out the 3 x 3 square which we made wxSmith start for us.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we want to display some floating point numbers in the grid. As we do so, we must deal with a dubious passage in the standard and most authoritative book on wxWidgets, ''Cross-Platform GUI Programming with wxWidgets'' by Smart and Hock. In the sole example given of a wxGrid, they write on page 348:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// We can specify that some cells will store numeric&lt;br /&gt;
// values rather than strings. Here we set grid column 5&lt;br /&gt;
// to hold floating point values displayed with width of 6&lt;br /&gt;
// and precision of 2&lt;br /&gt;
grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6, wxT(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This passage appears at least 18 times on the Internet without anyone observing that it is highly misleading if not dead wrong. To begin with, the last line is a little out of date and won't compile, at least not with Code::Blocks. It can be easily updated to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it does not illustrate the use of the SetColFormatFloat function. That command in the previous line applied to column 5 while this line puts a ''string'' – not a numeric value – into column 6, not 5. We can easily correct the column number:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 5,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it is still putting a wxString – not a numeric value, and certainly not a float – into the cell. It appears that the assertion that “some cells will store numeric values rather than strings” is highly confusing, not to say dead wrong. There is no elementary way to put anything other than a wxString into a cell of a wxGrid, nor to declare that a column will contain floats. The function of SetColFormatFloat() is quite different. The command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is used to give a uniform appearance to the column. It makes all strings in column 5 representing numbers appear with the same width and precision. Thus, after this command, the string “3.14159” in column 5 will appear as 3.14 and the string “3.1” will appear as 3.10.&lt;br /&gt;
&lt;br /&gt;
So then how do we show a floating point number in a wxGrid? We first have to convert it to a wxString and then put the string into the wxGrid. For example, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    float e = 2.71828;&lt;br /&gt;
    wxString cart;&lt;br /&gt;
    cart &amp;lt;&amp;lt; e;&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 5, cart); // To show what SetColFormatFloat does. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here ''cart'' is the wxString in which the numeric value of ''e'' rides into the grid. &lt;br /&gt;
&lt;br /&gt;
When these lines have been added to Barnum and the code compiled and run, we get the result shown below. Note that the floating point numbers appear with their full number of decimal places in column 4, but in column 5 they have been rounded to 2 decimal places as a result of the SetColFormatFloat() function.&lt;br /&gt;
&lt;br /&gt;
[[File : Squarepie.png  | |center|]]&lt;br /&gt;
&lt;br /&gt;
The wxString ''cart'' defined above can now be used over and over to carry numbers into the grid, as we illustrate here: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    short i,j;&lt;br /&gt;
    float xx;&lt;br /&gt;
&lt;br /&gt;
    for (i = 10; i &amp;lt;=12; i++){&lt;br /&gt;
        for (j = 10; j &amp;lt;= 12; j++){&lt;br /&gt;
            xx = i*j;&lt;br /&gt;
            xx = xx/2.;&lt;br /&gt;
            cart = wxString::Format(_T(&amp;quot;%8.2f&amp;quot;),xx);&lt;br /&gt;
            Grid1-&amp;gt;SetCellValue(i,j,cart);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result is shown below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
&lt;br /&gt;
[[File : xpy.png | |center]]&lt;br /&gt;
&lt;br /&gt;
As for the square of integers in the upper left corner of the grid, it is “magic”; all rows, columns and diagonals have the same sum. Anyone venturing into wxGrid land is going to need all the magic he can get. But studying Barnum.cpp or other wxSmith code should be helpful.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9244</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9244"/>
		<updated>2017-01-28T19:53:21Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and values numeric values in some elements of a 40x40 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The code written by wxSmith itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by variables in your program. The code wxSmith writes has the size of the grid given by two constants, the number of rows and the number of columns, but you can easily see from the code writtten by wxSmith how to make the grid's size depend on variables in your code. &lt;br /&gt;
    &lt;br /&gt;
So let's get started. Create a new wxWidgets application. Call it DiaGrid and make it frame-based. We don't want the grid showing all the time, only when we call it up, so we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid for the program.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch. (This was discovered by a lot of trial and error.)&lt;br /&gt;
&lt;br /&gt;
Note that we did not put scroll bars on any of the components we used. The wxGrid component automatically carries its own scroll bars and any others just make for confusion.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog containing the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the letters of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for present purposes.&lt;br /&gt;
&lt;br /&gt;
Now we put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line. Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
&lt;br /&gt;
Now let us have a look at the code wxSmith has written for us. It is in Barnum.cpp.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(300,200), 		&lt;br /&gt;
              wxFULL_REPAINT_ON_RESIZE, _T(&amp;quot;ID_GRID1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
	Grid1-&amp;gt;EnableEditing(false);&lt;br /&gt;
	Grid1-&amp;gt;EnableGridLines(true);&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We see immediately that wxSmith starts the row and column numbering from 0. Note how it set the values of the three elements in the 0th row with a call to SetCellValue(). The first two arguments in this call are the row and column number; the third must be a wxString – not a standard C string but a wxString. The _(&amp;quot; … &amp;quot;) structure converts what is inside the quotation marks to a wxString. &lt;br /&gt;
&lt;br /&gt;
Let's now add more data to our array with lines below the //*) which marks the end of the code wxSmith regards as its property. First we will fill out the 3 x 3 square which we made wxSmith start for us.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we want to display some floating point numbers in the grid. As we do so, we must deal with a dubious passage in the standard and most authoritative book on wxWidgets, ''Cross-Platform GUI Programming with wxWidgets'' by Smart and Hock. In the sole example given of a wxGrid, they write on page 348:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// We can specify that some cells will store numeric&lt;br /&gt;
// values rather than strings. Here we set grid column 5&lt;br /&gt;
// to hold floating point values displayed with width of 6&lt;br /&gt;
// and precision of 2&lt;br /&gt;
grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6, wxT(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This passage appears at least 18 times on the Internet without anyone observing that it is highly misleading if not dead wrong. To begin with, the last line is a little out of date and won't compile, at least not with Code::Blocks. It can be easily updated to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it does not illustrate the use of the SetColFormatFloat function. That command in the previous line applied to column 5 while this line puts a ''string'' – not a numeric value – into column 6, not 5. We can easily correct the column number:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 5,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it is still putting a wxString – not a numeric value, and certainly not a float – into the cell. It appears that the assertion that “some cells will store numeric values rather than strings” is highly confusing, not to say dead wrong. There is no elementary way to put anything other than a wxString into a cell of a wxGrid, nor to declare that a column will contain floats. The function of SetColFormatFloat() is quite different. The command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is used to give a uniform appearance to the column. It makes all strings in column 5 representing numbers appear with the same width and precision. Thus, after this command, the string “3.14159” in column 5 will appear as 3.14 and the string “3.1” will appear as 3.10.&lt;br /&gt;
&lt;br /&gt;
So then how do we show a floating point number in a wxGrid? We first have to convert it to a wxString and then put the string into the wxGrid. For example, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    float e = 2.71828;&lt;br /&gt;
    wxString cart;&lt;br /&gt;
    cart &amp;lt;&amp;lt; e;&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 5, cart); // To show what SetColFormatFloat does. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here ''cart'' is the wxString in which the numeric value of ''e'' rides into the grid. &lt;br /&gt;
&lt;br /&gt;
When these lines have been added to Barnum and the code compiled and run, we get the result shown below. Note that the floating point numbers appear with their full number of decimal places in column 4, but in column 5 they have been rounded to 2 decimal places as a result of the SetColFormatFloat() function.&lt;br /&gt;
&lt;br /&gt;
[[File : Squarepie.png  | |center|]]&lt;br /&gt;
&lt;br /&gt;
The wxString ''cart'' defined above can now be used over and over to carry numbers into the grid, as we illustrate here: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    short i,j;&lt;br /&gt;
    float xx;&lt;br /&gt;
&lt;br /&gt;
    for (i = 10; i &amp;lt;=12; i++){&lt;br /&gt;
        for (j = 10; j &amp;lt;= 12; j++){&lt;br /&gt;
            xx = i*j;&lt;br /&gt;
            xx = xx/2.;&lt;br /&gt;
            cart = wxString::Format(_T(&amp;quot;%8.2f&amp;quot;),xx);&lt;br /&gt;
            Grid1-&amp;gt;SetCellValue(i,j,cart);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result is shown below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
&lt;br /&gt;
[[File : xpy.png | |center]]&lt;br /&gt;
&lt;br /&gt;
As for the square of integers in the upper left corner of the grid, it is “magic”; all rows, columns and diagonals have the same sum. Anyone venturing into wxGrid land is going to need all the magic he can get. But studying Barnum.cpp or other wxSmith code should be helpful.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9243</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9243"/>
		<updated>2017-01-28T19:30:11Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and values in a 3x3 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The code written by wxSmith itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by some variable, say MySize, in your program. The code wxSmith writes has the size of the grid given by two constants, 40 x 40 in the example, but you can easily see from the wxSmith example how to make the grid's size depend on variables in your code. &lt;br /&gt;
    &lt;br /&gt;
So let's get started. Create a new wxWidgets application. Call it DiaGrid  and make it frame-based. We don't want the grid showing all the time, only when we call it up, so we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid for the program.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch. (This was discovered by a lot of trial and error.)&lt;br /&gt;
&lt;br /&gt;
Note that we did not put scroll bars on any of the components we used. The wxGrid component automatically carries its own scroll bars and any others just make for confusion.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog containing the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the letters of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for present purposes.&lt;br /&gt;
&lt;br /&gt;
Now we put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line.  Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
&lt;br /&gt;
Now let us have a look at the code wxSmith has written for us. It is in Barnum.cpp.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(300,200), 		&lt;br /&gt;
              wxFULL_REPAINT_ON_RESIZE, _T(&amp;quot;ID_GRID1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
	Grid1-&amp;gt;EnableEditing(false);&lt;br /&gt;
	Grid1-&amp;gt;EnableGridLines(true);&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We see immediately that wxSmith starts the row and column numbering from 0.  Note how it set the values of the three elements in the 0th row with a call to SetCellValue(). The first two arguments in this call are the row and column number; the third must be a wxString – not a standard C string but a wxString. The  _(&amp;quot; … &amp;quot;) structure converts what is inside the quotation marks to a wxString.  &lt;br /&gt;
&lt;br /&gt;
Let's now add  more data to our array with lines below the //*) which marks the end of the code wxSmith regards as its property. First we will fill out the 3 x 3 square which we made wxSmith start for us.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we want to display some floating point numbers in the grid. As we do so, we must deal with a dubious passage in the standard and most authoritative book on wxWidgets, ''Cross-Platform GUI Programming with wxWidgets'' by Smart and Hock. In the sole example given of a wxGrid, they write on page 348:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// We can specify that some cells will store numeric&lt;br /&gt;
// values rather than strings. Here we set grid column 5&lt;br /&gt;
// to hold floating point values displayed with width of 6&lt;br /&gt;
// and precision of 2&lt;br /&gt;
grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6, wxT(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This passage appears at least 18 times on the Internet without anyone observing that it is highly misleading if not dead wrong. To begin with, the last line is a little out of date and won't compile, at least not with Code::Blocks. It can be easily updated to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it does not illustrate the use of the SetColFormatFloat function. That command in the previous line applied to column 5 while this line puts a ''string'' – not a numeric value – into column 6, not 5. We can easily correct the column number:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 5,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it is still putting a wxString – not a numeric value, and certainly not a float – into the cell. It appears that the assertion that “some cells will store numeric values rather than strings” is highly confusing, not to say dead wrong. There is no elementary way to put anything other than a wxString into a cell of a wxGrid, nor to declare that a column will contain floats. The function of SetColFormatFloat() is quite different. The command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is used to give a uniform appearance to the column. It makes all strings in column 5 representing numbers appear with the same width and precision. Thus, after this command, the string “3.14159” in column 5 will appear as 3.14 and the string “3.1” will appear as 3.10.&lt;br /&gt;
&lt;br /&gt;
So then how do we show a floating point number in a wxGrid? We first have to convert it to a wxString and then put the string into the wxGrid. For example, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    float e = 2.71828;&lt;br /&gt;
    wxString cart;&lt;br /&gt;
    cart &amp;lt;&amp;lt; e;&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 5, cart); // To show what SetColFormatFloat does. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here ''cart'' is the wxString in which the numeric value of ''e'' rides into the grid. &lt;br /&gt;
&lt;br /&gt;
When these lines have been added to Barnum and the code compiled and run, we get the result shown below. Note that the floating point numbers appear with their full number of decimal places in column 4, but in column 5 they have been rounded to 2 decimal places as a result of the SetColFormatFloat() function.&lt;br /&gt;
&lt;br /&gt;
[[File : Squarepie.png  | |center|]]&lt;br /&gt;
&lt;br /&gt;
The wxString ''cart'' defined above can now be used over and over to carry numbers into the grid, as we illustrate here: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    short i,j;&lt;br /&gt;
    float xx;&lt;br /&gt;
&lt;br /&gt;
    for (i = 10; i &amp;lt;=12; i++){&lt;br /&gt;
        for (j = 10; j &amp;lt;= 12; j++){&lt;br /&gt;
            xx = i*j;&lt;br /&gt;
            xx = xx/2.;&lt;br /&gt;
            cart = wxString::Format(_T(&amp;quot;%8.2f&amp;quot;),xx);&lt;br /&gt;
            Grid1-&amp;gt;SetCellValue(i,j,cart);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result is shown below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
&lt;br /&gt;
[[File : xpy.png | |center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As for the square of integers in the upper left corner of the grid, it is “magic”; all rows, columns and diagonals have the same sum. Anyone venturing into wxGrid land is going to need all the magic he can get. But studying Barnum.cpp or other wxSmith code should be helpful.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9242</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9242"/>
		<updated>2017-01-28T19:22:17Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and values in a 3x3 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The code written by wxSmith itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by some variable, say MySize, in your program. The code wxSmith writes has the size of the grid given by two constants, 40 x 40 in the example, but you can easily see from the wxSmith example how to make the grid's size depend on variables in your code. &lt;br /&gt;
    &lt;br /&gt;
So let's get started. Create a new wxWidgets application. Call it DiaGrid  and make it frame-based. We don't want the grid showing all the time, only when we call it up, so we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid for the program.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch. (This was discovered by a lot of trial and error.)&lt;br /&gt;
&lt;br /&gt;
Note that we did not put scroll bars on any of the components we used. The wxGrid component automatically carries its own scroll bars and any others just make for confusion.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog containing the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the letters of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for present purposes.&lt;br /&gt;
&lt;br /&gt;
Now we put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line.  Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
&lt;br /&gt;
Now let us have a look at the code wxSmith has written for us. It is in Barnum.cpp&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(300,200), 		&lt;br /&gt;
              wxFULL_REPAINT_ON_RESIZE, _T(&amp;quot;ID_GRID1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
	Grid1-&amp;gt;EnableEditing(false);&lt;br /&gt;
	Grid1-&amp;gt;EnableGridLines(true);&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We see immediately that wxSmith starts the row and column numbering from 0.  Note how it set the values of the three elements in the 0th row with a call to SetCellValue(). The first two arguments in this call are the row and column number; the third must be a wxString – not a standard C string but a wxString. The  _(&amp;quot; … &amp;quot;) structure converts what is inside the quotation marks to a wxString.  &lt;br /&gt;
&lt;br /&gt;
Let's now add  more data to our array with lines below the //*) which marks the end of the code wxSmith regards as its property. First we will fill out the 3 x 3 square which we made wxSmith start for us.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we want to display some floating point numbers in the grid. As we do so, we must deal with a dubious passage in the standard and most authoritative book on wxWidgets, ''Cross-Platform GUI Programming with wxWidgets'' by Smart and Hock. In the sole example given of a wxGrid, they write on page 348:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// We can specify that some cells will store numeric&lt;br /&gt;
// values rather than strings. Here we set grid column 5&lt;br /&gt;
// to hold floating point values displayed with width of 6&lt;br /&gt;
// and precision of 2&lt;br /&gt;
grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6, wxT(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This passage appears at least 18 times on the Internet without anyone observing that it is highly misleading if not dead wrong. To begin with, the last line is a little out of date and won't compile, at least not with Code::Blocks. It can be easily updated to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it does not illustrate the use of the SetColFormatFloat function. That command in the previous line applied to column 5 while this line puts a ''string'' – not a numeric value – into column 6, not 5. We can easily correct the column number:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 5,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it is still putting a wxString – not a numeric value, and certainly not a float – into the cell. It appears that the assertion that “some cells will store numeric values rather than strings” is highly confusing, not to say dead wrong. There is no elementary way to put anything other than a wxString into a cell of a wxGrid, nor to declare that a column will contain floats. The function of SetColFormatFloat() is quite different. The command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is used to give a uniform appearance to the column. It makes all strings in column 5 representing numbers appear with the same width and precision. Thus, after this command, the string “3.14159” in column 5 will appear as 3.14 and the string “3.1” will appear as 3.10.&lt;br /&gt;
&lt;br /&gt;
So then how do we show a floating point number in a wxGrid? We first have to convert it to a wxString and then put the string into the wxGrid. For example, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    float e = 2.71828;&lt;br /&gt;
    wxString cart;&lt;br /&gt;
    cart &amp;lt;&amp;lt; e;&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 5, cart); // To show what SetColFormatFloat does. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here ''cart'' is the wxString in which the numeric value of ''e'' rides into the grid. &lt;br /&gt;
&lt;br /&gt;
When these lines have been added to Barnum and the code compiled and run, we get the result shown below. Note that the floating point numbers appear with their full number of decimal places in column 4, but in column 5 they have been rounded to 2 decimal places as a result of the SetColFormatFloat() function.&lt;br /&gt;
&lt;br /&gt;
[[File : Squarepie.png  | |center|]]&lt;br /&gt;
&lt;br /&gt;
The wxString ''cart'' defined above can now be used over and over to carry numbers into the grid, as we illustrate here: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    short i,j;&lt;br /&gt;
    float xx;&lt;br /&gt;
&lt;br /&gt;
    for (i = 10; i &amp;lt;=12; i++){&lt;br /&gt;
        for (j = 10; j &amp;lt;= 12; j++){&lt;br /&gt;
            xx = i*j;&lt;br /&gt;
            xx = xx/2.;&lt;br /&gt;
            cart = wxString::Format(_T(&amp;quot;%8.2f&amp;quot;),xx);&lt;br /&gt;
            Grid1-&amp;gt;SetCellValue(i,j,cart);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result is shown below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
&lt;br /&gt;
[[File : xpy.png | |center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As for the square of integers in the upper left corner of the grid, it is “magic”; all rows, columns and diagonals have the same sum. Anyone venturing into wxGrid land is going to need all the magic he can get. But studying the Barnum.cpp or other wxSmith code should be helpful.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9241</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9241"/>
		<updated>2017-01-28T18:58:58Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and values in a 3x3 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The code written by wxSmith itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by some variable, say MySize, in your program. The code wxSmith writes has the size of the grid as a fixed constant, say 15, but you can easily see from the wxSmith example how to make the grid's size depend on MySize in your code. &lt;br /&gt;
    &lt;br /&gt;
Create a new wxWidgets application. Call it DiaGrid  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to show a grid that shows data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch.&lt;br /&gt;
&lt;br /&gt;
Note that we did not put scroll bars on any of the components we used. The wxGrid component automatically carries its own scroll bars and any others just make for confusion.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog with the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the letters of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for present purposes.&lt;br /&gt;
&lt;br /&gt;
Now we put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line.  Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
&lt;br /&gt;
Now let us have a look at the code wxSmith has written for us. It is in Barnum.cpp&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(300,200), 		&lt;br /&gt;
              wxFULL_REPAINT_ON_RESIZE, _T(&amp;quot;ID_GRID1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
	Grid1-&amp;gt;EnableEditing(false);&lt;br /&gt;
	Grid1-&amp;gt;EnableGridLines(true);&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We see immediately that wxSmith starts the row and column numbering from 0.  Note how it set the values of the three elements in the 0th row with a call to SetCellValue(). The first two arguments in this call are the row and column number; the third must be a wxString – not a standard C string but a wxString. The  _(&amp;quot; … &amp;quot;) structure converts what is inside the quotation marks to a wxString.  &lt;br /&gt;
&lt;br /&gt;
Let's now add  more data to our array with lines below the //*) which marks the end of the code wxSmith regards as its property. First we will fill out the 3 x 3 square which we made wxSmith start for us.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we want to display some floating point numbers in the grid. As we do so, we must deal with a dubious passage in the standard and most authoritative book on wxWidgets, ''Cross-Platform GUI Programming with wxWidgets'' by Smart and Hock. In the sole example given of a wxGrid, they write on page 348:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// We can specify that some cells will store numeric&lt;br /&gt;
// values rather than strings. Here we set grid column 5&lt;br /&gt;
// to hold floating point values displayed with width of 6&lt;br /&gt;
// and precision of 2&lt;br /&gt;
grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6, wxT(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This passage appears at least 18 times on the Internet without anyone observing that it is highly misleading if not dead wrong. To begin with, the last line is a little out of date and won't compile, at least not with Code::Blocks. It can be easily updated to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it does not illustrate the use of the SetColFormatFloat function. That command in the previous line applied to column 5 while this line puts a ''string'' – not a numeric value – into column 6, not 5. We can easily correct the column number:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 5,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it is still putting a wxString – not a numeric value, and certainly not a float – into the cell. It appears that the assertion that “some cells will store numeric values rather than strings” is highly confusing, not to say dead wrong. There is no elementary way to put anything other than a wxString into a cell of a wxGrid, nor to declare that a column will contain floats. The function of SetColFormatFloat() is quite different. The command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is used to give a uniform appearance to the column. It makes all strings in column 5 representing numbers appear with the same width and precision. Thus, after this command, the string “3.14159” in column 5 will appear as 3.14 and the string “3.1” will appear as 3.10.&lt;br /&gt;
&lt;br /&gt;
So then how do we show a floating point number in a wxGrid? We first have to convert it to a wxString and then put the string into the wxGrid. For example, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    float e = 2.71828;&lt;br /&gt;
    wxString cart;&lt;br /&gt;
    cart &amp;lt;&amp;lt; e;&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 5, cart); // To show what SetColFormatFloat does. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here ''cart'' is the wxString in which the numeric value of ''e'' rides into the grid. &lt;br /&gt;
&lt;br /&gt;
When these lines have been added to Barnum and the code compiled and run, we get the result shown below. Note that the floating point numbers appear with their full number of decimal places in column 4, but in column 5 they have been rounded to 2 decimal places as a result of the SetColFormatFloat() function.&lt;br /&gt;
&lt;br /&gt;
[[File : Squarepie.png  | |center|]]&lt;br /&gt;
&lt;br /&gt;
The wxString ''cart'' defined above can now be used over and over to carry numbers into the grid, as we illustrate here: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    short i,j;&lt;br /&gt;
    float xx;&lt;br /&gt;
&lt;br /&gt;
    for (i = 10; i &amp;lt;=12; i++){&lt;br /&gt;
        for (j = 10; j &amp;lt;= 12; j++){&lt;br /&gt;
            xx = i*j;&lt;br /&gt;
            xx = xx/2.;&lt;br /&gt;
            cart = wxString::Format(_T(&amp;quot;%8.2f&amp;quot;),xx);&lt;br /&gt;
            Grid1-&amp;gt;SetCellValue(i,j,cart);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result is shown below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
&lt;br /&gt;
[[File : xpy.png | |center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As for the square of integers in the upper left corner of the grid, it is “magic”; all rows, columns and diagonals have the same sum. Anyone venturing into wxGrid land is going to need all the magic he can get. But studying the Barnum.cpp or other wxSmith code should be helpful.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9240</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9240"/>
		<updated>2017-01-25T21:06:29Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and values in a 3x3 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The wxSmith code itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by some variable, say MySize, in your program. The code wxSmith writes has the size of the grid as a fixed constant, say 15, but you can easily see from the wxSmith example how to make the grid's size depend on MySize in your code. &lt;br /&gt;
    &lt;br /&gt;
Create a new wxWidgets application. Call it DiaGrid  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to show a grid that shows data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch.&lt;br /&gt;
&lt;br /&gt;
Note that we did not put scroll bars on any of the components we used. The wxGrid component automatically carries its own scroll bars and any others just make for confusion.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog with the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the letters of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for present purposes.&lt;br /&gt;
&lt;br /&gt;
Now we put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line.  Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
&lt;br /&gt;
Now let us have a look at the code wxSmith has written for us. It is in Barnum.cpp&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(300,200), 		&lt;br /&gt;
              wxFULL_REPAINT_ON_RESIZE, _T(&amp;quot;ID_GRID1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
	Grid1-&amp;gt;EnableEditing(false);&lt;br /&gt;
	Grid1-&amp;gt;EnableGridLines(true);&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We see immediately that wxSmith starts the row and column numbering from 0.  Note how it set the values of the three elements in the 0th row with a call to SetCellValue(). The first two arguments in this call are the row and column number; the third must be a wxString – not a standard C string but a wxString. The  _(&amp;quot; … &amp;quot;) structure converts what is inside the quotation marks to a wxString.  &lt;br /&gt;
&lt;br /&gt;
Let's now add  more data to our array with lines below the //*) which marks the end of the code wxSmith regards as its property. First we will fill out the 3 x 3 square which we made wxSmith start for us.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we want to display some floating point numbers in the grid. As we do so, we must deal with a dubious passage in the standard and most authoritative book on wxWidgets, ''Cross-Platform GUI Programming with wxWidgets'' by Smart and Hock. In the sole example given of a wxGrid, they write on page 348, (with correction of a typo):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// We can specify that some cells will store numeric&lt;br /&gt;
// values rather than strings. Here we set grid column 5&lt;br /&gt;
// to hold floating point values displayed with width of 6&lt;br /&gt;
// and precision of 2&lt;br /&gt;
grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6, &amp;quot;3.1415&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This passage appears at least 18 times on the Internet without anyone observing that it is highly misleading if not dead wrong. To begin with, the last line is out of date and won't compile, at least not with Code::Blocks. It can be easily updated to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it does not illustrate the use of the SetColFormatFloat function. That command in the previous line applied to column 5 while this line puts a ''string'' – not a numeric value – into column 6, not 5. We can easily correct the column number:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 5,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it is still putting a wxString – not a numeric value, and certainly not a float – into the cell. It turns out that the assertion that “some cells will store numeric values rather than strings” is highly confusing, not to say dead wrong. There is no elementary way to put anything other than a wxString into a cell of a wxGrid, nor to declare that a column will contain floats. The function of SetColFormatFloat() is quite different. The command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is used to give a uniform appearance to the column. It makes all strings in column 5 representing numbers appear with the same width and precision. Thus, after this command, the string “3.14159” in column 5 will appear as 3.14 and the string “3.1” will appear as 3.10.&lt;br /&gt;
&lt;br /&gt;
So then how do we show a floating point number in a wxGrid? We first have to convert it to a wxString and then put the string into the wxGrid. For example, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    float e = 2.71828;&lt;br /&gt;
    wxString cart;&lt;br /&gt;
    cart &amp;lt;&amp;lt; e;&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 5, cart); // To show what SetColFormatFloat does. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here ''cart'' is the wxString in which the numeric value of ''e'' rides into the grid. Note that ''cart'' could be used over and over to carry all members of a matrix, one by one, into the grid. &lt;br /&gt;
&lt;br /&gt;
When these lines have been added to Barnum and the code compiled and run, we get the result shown below. Note that the floating point numbers appear with their full number of decimal places in column 4, but in column 5 they have been rounded to 2 decimal places as a result of the SetColFormatFloat() function.&lt;br /&gt;
&lt;br /&gt;
[[File : Squarepie.png  | |center|]]&lt;br /&gt;
&lt;br /&gt;
The wxString ''cart'' can be used over and over to carry numbers into the grid, as we illustrate here: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    short i,j;&lt;br /&gt;
    float xx;&lt;br /&gt;
&lt;br /&gt;
    for (i = 10; i &amp;lt;=12; i++){&lt;br /&gt;
        for (j = 10; j &amp;lt;= 12; j++){&lt;br /&gt;
            xx = i*j;&lt;br /&gt;
            xx = xx/2.;&lt;br /&gt;
            cart = wxString::Format(_T(&amp;quot;%8.2f&amp;quot;),xx);&lt;br /&gt;
            Grid1-&amp;gt;SetCellValue(i,j,cart);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result is shown below, where the window has been scrolled over and down to show the rectangle where the above code put numbers. &lt;br /&gt;
&lt;br /&gt;
[[File : xpy.png | |center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As for the square of integers in the upper left corner of the grid, it is “magic”; all rows, columns and diagonals have the same sum. Anyone entering wxGrid land is going to need all the magic he can get. But studying the Barnum.cpp code should be helpful.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=File:Xpy.png&amp;diff=9239</id>
		<title>File:Xpy.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=File:Xpy.png&amp;diff=9239"/>
		<updated>2017-01-25T20:49:30Z</updated>

		<summary type="html">&lt;p&gt;Grouch: Illustration for wxSmith tutorial 10.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Illustration for wxSmith tutorial 10.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9237</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9237"/>
		<updated>2017-01-23T00:24:00Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and values in a 3x3 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The wxSmith code itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by some variable, say MySize, in your program. The code wxSmith writes has the size of the grid as a fixed constant, say 15, but you can easily see from the wxSmith example how to make the grid's size depend on MySize in your code. &lt;br /&gt;
    &lt;br /&gt;
Create a new wxWidgets application. Call it DiaGrid  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to show a grid that shows data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch.&lt;br /&gt;
&lt;br /&gt;
Note that we did not put scroll bars on any of the components we used. The wxGrid component automatically carries its own scroll bars and any others just make for confusion.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog with the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the letters of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for present purposes.&lt;br /&gt;
&lt;br /&gt;
Now we put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line.  Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
&lt;br /&gt;
Now let us have a look at the code wxSmith has written for us. It is in Barnum.cpp&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(300,200), 		&lt;br /&gt;
              wxFULL_REPAINT_ON_RESIZE, _T(&amp;quot;ID_GRID1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
	Grid1-&amp;gt;EnableEditing(false);&lt;br /&gt;
	Grid1-&amp;gt;EnableGridLines(true);&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We see immediately that wxSmith starts the row and column numbering from 0.  Note how it set the values of the three elements in the 0th row with a call to SetCellValue(). The first two arguments in this call are the row and column number; the third must be a wxString – not a standard C string but a wxString. The  _(&amp;quot; … &amp;quot;) structure converts what is inside the quotation marks to a wxString.  &lt;br /&gt;
&lt;br /&gt;
Let's now add  more data to our array with lines below the //*) which marks the end of the code wxSmith regards as its property. First we will fill out the 3 x 3 square which we made wxSmith start for us.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we want to display some floating point numbers in the grid. As we do so, we must deal with a dubious passage in the standard and most authoritative book on wxWidgets, ''Cross-Platform GUI Programming with wxWidgets'' by Smart and Hock. In the sole example given of a wxGrid, they write on page 348, (with correction of a typo):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// We can specify that some cells will store numeric&lt;br /&gt;
// values rather than strings. Here we set grid column 5&lt;br /&gt;
// to hold floating point values displayed with width of 6&lt;br /&gt;
// and precision of 2&lt;br /&gt;
grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6, &amp;quot;3.1415&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This passage appears at least 18 times on the Internet without anyone observing that it is highly misleading if not dead wrong. To begin with, the last line is out of date and won't compile, at least not with Code::Blocks. It can be easily updated to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it does not illustrate the use of the SetColFormatFloat function. That command in the previous line applied to column 5 while this line puts a ''string'' – not a numeric value – into column 6, not 5. We can easily correct the column number:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 5,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it is still putting a wxString – not a numeric value, and certainly not a float – into the cell. It turns out that the assertion that “some cells will store numeric values rather than strings” is highly confusing, not to say dead wrong. There is no elementary way to put anything other than a wxString into a cell of a wxGrid, nor to declare that a column will contain floats. The function of SetColFormatFloat() is quite different. The command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is used to give a uniform appearance to the column. It makes all strings in column 5 representing numbers appear with the same width and precision. Thus, after this command, the string “3.14159” in column 5 will appear as 3.14 and the string “3.1” will appear as 3.10.&lt;br /&gt;
&lt;br /&gt;
So then how do we show a floating point number in a wxGrid? We first have to convert it to a wxString and then put the string into the wxGrid. For example, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    float e = 2.71828;&lt;br /&gt;
    wxString cart;&lt;br /&gt;
    cart &amp;lt;&amp;lt; e;&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 5, cart); // To show what SetColFormatFloat does. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here ''cart'' is the wxString in which the numeric value of ''e'' rides into the grid. Note that ''cart'' could be used over and over to carry all members of a matrix, one by one, into the grid. &lt;br /&gt;
&lt;br /&gt;
When these lines have been added to Barnum and the code compiled and run, we get the result shown below. Note that the floating point numbers appear with their full number of decimal places in column 4, but in column 5 they have been rounded to 2 decimal places as a result of the SetColFormatFloat() function.&lt;br /&gt;
&lt;br /&gt;
[[File : Squarepie.png  | |center|]]&lt;br /&gt;
&lt;br /&gt;
As for the square of integers, it is “magic”; all rows, columns and diagonals have the same sum. Anyone entering wxGrid land is going to need all the magic he can get. But studying the Barnum.cpp code should be helpful.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9236</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9236"/>
		<updated>2017-01-23T00:09:27Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and values in a 3x3 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The wxSmith code itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by some variable, say MySize, in your program. The code wxSmith writes has the size of the grid as a fixed constant, say 15, but you can easily see from the wxSmith example how to make the grid's size depend on MySize in your code. &lt;br /&gt;
    &lt;br /&gt;
Create a new wxWidgets application. Call it DiaGrid  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to show a grid that shows data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog with the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the letters of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for present purposes.&lt;br /&gt;
&lt;br /&gt;
Now we put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line.  Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
&lt;br /&gt;
Now let us have a look at the code wxSmith has written for us. It is in Barnum.cpp&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(300,200), 		&lt;br /&gt;
              wxFULL_REPAINT_ON_RESIZE, _T(&amp;quot;ID_GRID1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
	Grid1-&amp;gt;EnableEditing(false);&lt;br /&gt;
	Grid1-&amp;gt;EnableGridLines(true);&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We see immediately that wxSmith starts the row and column numbering from 0.  Note how it set the values of the three elements in the 0th row with a call to SetCellValue(). The first two arguments in this call are the row and column number; the third must be a wxString – not a standard C string but a wxString. The  _(&amp;quot; … &amp;quot;) structure converts what is inside the quotation marks to a wxString.  &lt;br /&gt;
&lt;br /&gt;
Let's now add  more data to our array with lines below the //*) which marks the end of the code wxSmith regards as its property. First we will fill out the 3 x 3 square which we made wxSmith start for us.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we want to display some floating point numbers in the grid. As we do so, we must deal with a dubious passage in the standard and most authoritative book on wxWidgets, ''Cross-Platform GUI Programming with wxWidgets'' by Smart and Hock. In the sole example given of a wxGrid, they write on page 348, (with correction of a typo):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// We can specify that some cells will store numeric&lt;br /&gt;
// values rather than strings. Here we set grid column 5&lt;br /&gt;
// to hold floating point values displayed with width of 6&lt;br /&gt;
// and precision of 2&lt;br /&gt;
grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6, &amp;quot;3.1415&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This passage appears at least 18 times on the Internet without anyone observing that it is highly misleading if not dead wrong. To begin with, the last line is out of date and won't compile, at least not with Code::Blocks. It can be easily updated to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it does not illustrate the use of the SetColFormatFloat function. That command in the previous line applied to column 5 while this line puts a ''string'' – not a numeric value – into column 6, not 5. We can easily correct the column number:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 5,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it is still putting a wxString – not a numeric value, and certainly not a float – into the cell. It turns out that the assertion that “some cells will store numeric values rather than strings” is highly confusing, not to say dead wrong. There is no elementary way to put anything other than a wxString into a cell of a wxGrid, nor to declare that a column will contain floats. The function of SetColFormatFloat() is quite different. The command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is used to give a uniform appearance to the column. It makes all strings in column 5 representing numbers appear with the same width and precision. Thus, after this command, the string “3.14159” in column 5 will appear as 3.14 and the string “3.1” will appear as 3.10.&lt;br /&gt;
&lt;br /&gt;
So then how do we show a floating point number in a wxGrid? We first have to convert it to a wxString and then put the string into the wxGrid. For example, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    float e = 2.71828;&lt;br /&gt;
    wxString cart;&lt;br /&gt;
    cart &amp;lt;&amp;lt; e;&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 5, cart); // To show what SetColFormatFloat does. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here ''cart'' is the wxString in which the numeric value of ''e'' rides into the grid. Note that ''cart'' could be used over and over to carry all members of a matrix, one by one, into the grid. &lt;br /&gt;
&lt;br /&gt;
When these lines have been added to Barnum and the code compiled and run, we get the result shown below. Note that the floating point numbers appear with their full number of decimal places in column 4, but in column 5 they have been rounded to 2 decimal places as a result of the SetColFormatFloat() function.&lt;br /&gt;
&lt;br /&gt;
[[File : Squarepie.png]]&lt;br /&gt;
&lt;br /&gt;
As for the square of integers, it is “magic”; all rows, columns and diagonals have the same sum. Anyone entering wxGrid land is going to need all the magic he can get. But studying the Barnum.cpp code should be helpful.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=File:Squarepie.png&amp;diff=9235</id>
		<title>File:Squarepie.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=File:Squarepie.png&amp;diff=9235"/>
		<updated>2017-01-23T00:06:31Z</updated>

		<summary type="html">&lt;p&gt;Grouch: For wxSmith Tutorial 10.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For wxSmith Tutorial 10.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9234</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9234"/>
		<updated>2017-01-23T00:04:04Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and values in a 3x3 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The wxSmith code itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by some variable, say MySize, in your program. The code wxSmith writes has the size of the grid as a fixed constant, say 15, but you can easily see from the wxSmith example how to make the grid's size depend on MySize in your code. &lt;br /&gt;
    &lt;br /&gt;
Create a new wxWidgets application. Call it DiaGrid  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to show a grid that shows data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog with the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the letters of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for present purposes.&lt;br /&gt;
&lt;br /&gt;
Now we put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line.  Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
&lt;br /&gt;
Now let us have a look at the code wxSmith has written for us. It is in Barnum.cpp&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(300,200), 		&lt;br /&gt;
              wxFULL_REPAINT_ON_RESIZE, _T(&amp;quot;ID_GRID1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
	Grid1-&amp;gt;EnableEditing(false);&lt;br /&gt;
	Grid1-&amp;gt;EnableGridLines(true);&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We see immediately that wxSmith starts the row and column numbering from 0.  Note how it set the values of the three elements in the 0th row with a call to SetCellValue(). The first two arguments in this call are the row and column number; the third must be a wxString – not a standard C string but a wxString. The  _(&amp;quot; … &amp;quot;) structure converts what is inside the quotation marks to a wxString.  &lt;br /&gt;
&lt;br /&gt;
Let's now add  more data to our array with lines below the //*) which marks the end of the code wxSmith regards as its property. First we will fill out the 3 x 3 square which we made wxSmith start for us.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we want to display some floating point numbers in the grid. As we do so, we must deal with a dubious passage in the standard and most authoritative book on wxWidgets, ''Cross-Platform GUI Programming with wxWidgets'' by Smart and Hock. In the sole example given of a wxGrid, they write on page 348, (with correction of a typo):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// We can specify that some cells will store numeric&lt;br /&gt;
// values rather than strings. Here we set grid column 5&lt;br /&gt;
// to hold floating point values displayed with width of 6&lt;br /&gt;
// and precision of 2&lt;br /&gt;
grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6, &amp;quot;3.1415&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This passage appears at least 18 times on the Internet without anyone observing that it is highly misleading if not dead wrong. To begin with, the last line is out of date and won't compile, at least not with Code::Blocks. It can be easily updated to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it does not illustrate the use of the SetColFormatFloat function. That command in the previous line applied to column 5 while this line puts a ''string'' – not a numeric value – into column 6, not 5. We can easily correct the column number:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 5,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it is still putting a wxString – not a numeric value, and certainly not a float – into the cell. It turns out that the assertion that “some cells will store numeric values rather than strings” is highly confusing, not to say dead wrong. There is no elementary way to put anything other than a wxString into a cell of a wxGrid, nor to declare that a column will contain floats. The function of SetColFormatFloat() is quite different. The command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is used to give a uniform appearance to the column. It makes all strings in column 5 representing numbers appear with the same width and precision. Thus, after this command, the string “3.14159” in column 5 will appear as 3.14 and the string “3.1” will appear as 3.10.&lt;br /&gt;
&lt;br /&gt;
So then how do we show a floating point number in a wxGrid? We first have to convert it to a wxString and then put the string into the wxGrid. For example, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    float e = 2.71828;&lt;br /&gt;
    wxString cart;&lt;br /&gt;
    cart &amp;lt;&amp;lt; e;&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 5, cart); // To show what SetColFormatFloat does. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here ''cart'' is the wxString in which the numeric value of ''e'' rides into the grid. Note that ''cart'' could be used over and over to carry all members of a matrix, one by one, into the grid. &lt;br /&gt;
&lt;br /&gt;
When these lines have been added to Barnum and the code compiled and run, we get the result shown below. Note that the floating point numbers appear with their full number of decimal places in column 4, but in column 5 they have been rounded to 2 decimal places as a result of the SetColFormatFloat() function.&lt;br /&gt;
&lt;br /&gt;
As for the square of integers, it is “magic”; all rows, columns and diagonals have the same sum. Anyone entering wxGrid land is going to need all the magic he can get. But studying the Barnum.cpp code should be helpful.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9233</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9233"/>
		<updated>2017-01-22T23:57:08Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and values in a 3x3 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The wxSmith code itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by some variable, say MySize, in your program. The code wxSmith writes has the size of the grid as a fixed constant, say 15, but you can easily see from the wxSmith example how to make the grid's size depend on MySize in your code. &lt;br /&gt;
    &lt;br /&gt;
Create a new wxWidgets application. Call it DiaGrid  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to show a grid that shows data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog with the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the letters of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for present purposes.&lt;br /&gt;
&lt;br /&gt;
Now we put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line.  Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
&lt;br /&gt;
Now let us have a look at the code wxSmith has written for us. It is in Barnum.cpp&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(300,200), 		&lt;br /&gt;
              wxFULL_REPAINT_ON_RESIZE, _T(&amp;quot;ID_GRID1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
	Grid1-&amp;gt;EnableEditing(false);&lt;br /&gt;
	Grid1-&amp;gt;EnableGridLines(true);&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We see immediately that wxSmith starts the row and column numbering from 0.  Note how it set the values of the three elements in the 0th row with a call to SetCellValue(). The first two arguments in this call are the row and column number; the third must be a wxString – not a standard C string but a wxString. The  _(&amp;quot; … &amp;quot;) structure converts what is inside the quotation marks to a wxString.  &lt;br /&gt;
&lt;br /&gt;
Let's now add  more data to our array with lines below the //*) which marks the end of the code wxSmith regards as its property. First we will fill out the 3 x 3 square which we made wxSmith start for us.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
		Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we want to display some floating point numbers in the grid. As we do so, we must deal with a dubious passage in the standard and most authoritative book on wxWidgets, ''Cross-Platform GUI Programming with wxWidgets'' by Smart and Hock. In the sole example given of a wxGrid, they write on page 348, (with correction of a typo):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// We can specify that some cells will store numeric&lt;br /&gt;
// values rather than strings. Here we set grid column 5&lt;br /&gt;
// to hold floating point values displayed with width of 6&lt;br /&gt;
// and precision of 2&lt;br /&gt;
grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6, &amp;quot;3.1415&amp;quot;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This passage appears at least 18 times on the Internet without anyone observing that it is highly misleading if not dead wrong. To begin with, the last line is out of date and won't compile, at least not with Code::Blocks. It can be easily updated to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 6,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it does not illustrate the use of the SetColFormatFloat function. That command in the previous line applied to column 5 while this line puts a ''string'' – not a numeric value – into column 6, not 5. We can easily correct the column number:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;  &lt;br /&gt;
grid-&amp;gt;SetCellValue(0, 5,_(&amp;quot;3.1415&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But it is still putting a wxString – not a numeric value, and certainly not a float – into the cell. It turns out that the assertion that “some cells will store numeric values rather than strings” is highly confusing, not to say dead wrong. There is no elementary way to put anything other than a wxString into a cell of a wxGrid, nor to declare that a column will contain floats. The function of SetColFormatFloat() is quite different. The command &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	grid-&amp;gt;SetColFormatFloat(5, 6, 2);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
is used to give a uniform appearance to the column. It makes all strings in column 5 representing numbers appear with the same width and precision. Thus, after this command, the string “3.14159” in column 5 will appear as 3.14 and the string “3.1” will appear as 3.10.&lt;br /&gt;
&lt;br /&gt;
So then how do we show a floating point number in a wxGrid? We first have to convert it to a wxString and then put the string into the wxGrid. For example, &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    float e = 2.71828;&lt;br /&gt;
    wxString cart;&lt;br /&gt;
    cart &amp;lt;&amp;lt; e;&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 4, cart);&lt;br /&gt;
    Grid1-&amp;gt;SetCellValue(1, 5, cart); // To show what SetColFormatFloat does. &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here ''cart'' is the wxString in which the numeric value of ''e'' rides into the grid. Note that ''cart'' could be used over and over to carry all members of a matrix, one by one, into the grid. &lt;br /&gt;
&lt;br /&gt;
When these lines have been added to Barnum and the code compiled and run, we get the result shown below. Note that the floating point numbers appear with their full number of decimal places in column 4, but in column 5 they have been rounded to 2 decimal places as a result of the SetColFormatFloat()  functions.&lt;br /&gt;
&lt;br /&gt;
As for the square of integers, it is “magic”; all rows, columns and diagonals have the same sum. Anyone entering wxGrid land is going to need all the magic he can get. But studying the Barnum.cpp code should be helpful.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9229</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9229"/>
		<updated>2017-01-18T20:59:23Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and values in a 3x3 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The wxSmith code itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by some variable, say MySize, in your program. The code wxSmith writes has the size of the grid as a fixed constant, say 15, but you can easily see from the wxSmith example how to make the grid's size depend on MySize in your code. &lt;br /&gt;
    &lt;br /&gt;
Create a new wxWidgets application. Call it DiaGrid  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to show a grid that shows data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog with the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the letters of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for present purposes.&lt;br /&gt;
Now we put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line.  Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
Now let us have a look at the code wxSmith has written for us. It is in Barnum.cpp&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(300,200), 		&lt;br /&gt;
              wxFULL_REPAINT_ON_RESIZE, _T(&amp;quot;ID_GRID1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
	Grid1-&amp;gt;EnableEditing(false);&lt;br /&gt;
	Grid1-&amp;gt;EnableGridLines(true);&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));&lt;br /&gt;
	...	&lt;br /&gt;
	Grid1-&amp;gt;SetRowLabelValue(0, _(&amp;quot;zeta&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetRowLabelValue(1, _(&amp;quot;eta&amp;quot;));&lt;br /&gt;
	...&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 0, _(&amp;quot;2&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 1, _(&amp;quot;7&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 2, _(&amp;quot;6&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We see immediately that wxSmith starts the row and column numbering from 0.  Note how it set the values of the three elements in the 0th row. Let's now add two more rows to our array with these lines below the //*):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now save Barnum.cpp and click the Compile-and-run button. When you show the grid, you should see something like this.&lt;br /&gt;
&lt;br /&gt;
[[File : MagicSquare.png  | |center|]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The numbers of course form the magic square; all rows, columns and diagonals have the same sum. Anyone adventuring into wxGrid land is going to need all the magic he can get. But studying the Barnum.cpp code should help.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=File:MagicSquare.png&amp;diff=9228</id>
		<title>File:MagicSquare.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=File:MagicSquare.png&amp;diff=9228"/>
		<updated>2017-01-18T20:51:15Z</updated>

		<summary type="html">&lt;p&gt;Grouch: Illustration for wxSmith Tutorial 10  on wxGrid. Grid shows numbers.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Illustration for wxSmith Tutorial 10  on wxGrid. Grid shows numbers.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9227</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9227"/>
		<updated>2017-01-18T20:35:13Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and values in a 3x3 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The wxSmith code itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by some variable, say MySize, in your program. The code wxSmith writes has the size of the grid as a fixed constant, say 15, but you can easily see from the wxSmith example how to make the grid's size depend on MySize in your code. &lt;br /&gt;
    &lt;br /&gt;
Create a new wxWidgets application. Call it DiaGrid  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to show a grid that shows data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog with the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next. Let's make wxSmith get us started. &lt;br /&gt;
&lt;br /&gt;
First, let's label the rows and columns of the grid. In the Resources tab of the Management pane, click on Grid1. Scroll down in the properties window until you come to “Column Labels” and then click on the little square at the right end of the line. A window drops down and you enter labels for the columns, one per line. I just used the names of the letters of the first few letters of the Greek alphabet; three or four lines is enough for our present purposes. Then click on the next line in the properties box, “Row Labels”, again click on the little square at the right end of the line and enter row labels, one per line. I just used another string of letters in the Greek alphabet. Four or five is enough for present purposes.&lt;br /&gt;
Now we put some values in the cells. The next row down in the properties box is “Cell Data”. Again click the little square at the right end of the line.  Enter 2, 7, and 6 on successive lines. These will go into the first row. Since we have set the number of columns to 40, we would have to add 37 more lines to get to the second row. We will get there by a different route.&lt;br /&gt;
Now let us have a look at the code wxSmith has written for us. It is in Barnum.cpp&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(300,200), 		&lt;br /&gt;
              wxFULL_REPAINT_ON_RESIZE, _T(&amp;quot;ID_GRID1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;CreateGrid(40,40);&lt;br /&gt;
	Grid1-&amp;gt;EnableEditing(false);&lt;br /&gt;
	Grid1-&amp;gt;EnableGridLines(true);&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(0, _(&amp;quot;alpha&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetColLabelValue(1, _(&amp;quot;beta&amp;quot;));&lt;br /&gt;
	...	&lt;br /&gt;
	Grid1-&amp;gt;SetRowLabelValue(0, _(&amp;quot;zeta&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetRowLabelValue(1, _(&amp;quot;eta&amp;quot;));&lt;br /&gt;
	...&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 0, _(&amp;quot;2&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 1, _(&amp;quot;7&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(0, 2, _(&amp;quot;6&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We see immediately that wxSmith starts the row and column numbering from 0.  Note how it set the values of the three elements in the 0th row. Let's now add two more rows to our array with these lines below the //*):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 0, _(&amp;quot;9&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 1, _(&amp;quot;5&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(1, 2, _(&amp;quot;1&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 0, _(&amp;quot;4&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 1, _(&amp;quot;3&amp;quot;));&lt;br /&gt;
	Grid1-&amp;gt;SetCellValue(2, 2, _(&amp;quot;8&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now save Barnum.cpp and click the Compile-and-run button. When you show the grid, you should see something like this.&lt;br /&gt;
&lt;br /&gt;
The numbers of course form the magic square; all rows, columns and diagonals have the same sum. Anyone adventuring into wxGrid land is going to need all the magic he can get. But studying the Barnum.cpp code should be helpful.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9226</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9226"/>
		<updated>2017-01-18T20:08:30Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process. At the end, we will have a scrollable grid with names on the columns and rows and values in a 3x3 matrix. &lt;br /&gt;
 &lt;br /&gt;
Probably the most valuable use of the code that wxSmith writes for us is as an example of how to use wxGrid. When Smart and Hock get around to describing it on page 346, they seem to have run out of energy for making up clear, complete examples. wxSmith can come to their rescue with nice examples. The wxSmith code itself, however, is not likely to go directly into your final program. For example, you may well want the size of the grid to be determined by some variable, say MySize, in your program. The code wxSmith writes has the size of the grid as a fixed constant, say 15, but you can easily see from the wxSmith example how to make the grid's size depend on MySize in your code. &lt;br /&gt;
    &lt;br /&gt;
Create a new wxWidgets application. Call it DiaGrid  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to show a grid that shows data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog with the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9225</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9225"/>
		<updated>2017-01-17T03:36:07Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
&lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process, and it is but a work in progress. At present, it shows how to create a grid with scroll bars with wxSmith and how to display it from a running program with the click of a button. But so far, the grid is all blank; putting data into it and getting that data displayed properly is the next step.  &lt;br /&gt;
&lt;br /&gt;
Create a new wxWidgets application. Call it DiaGrid and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid. &lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png | |right|]]&lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog with the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png | |center|]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=File:DiaGridManagementPane.png&amp;diff=9224</id>
		<title>File:DiaGridManagementPane.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=File:DiaGridManagementPane.png&amp;diff=9224"/>
		<updated>2017-01-17T03:15:10Z</updated>

		<summary type="html">&lt;p&gt;Grouch: Part of wxSmith Tutorial 10&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Part of wxSmith Tutorial 10&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9223</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9223"/>
		<updated>2017-01-17T03:06:52Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
&lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process, and it is but a work in progress. At present, it shows how to create a grid with scroll bars with wxSmith and how to display it from a running program with the click of a button. But so far, the grid is all blank; putting data into it and getting that data displayed properly is the next step.  &lt;br /&gt;
&lt;br /&gt;
Create a new wxWidgets application. Call it DiaGrid and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid. &lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridManagementPane.png]]&lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog with the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9222</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9222"/>
		<updated>2017-01-17T02:35:40Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
&lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process, and it is but a work in progress. At present, it shows how to create a grid with scroll bars with wxSmith and how to display it from a running program with the click of a button. But so far, the grid is all blank; putting data into it and getting that data displayed properly is the next step.  &lt;br /&gt;
&lt;br /&gt;
Create a new wxWidgets application. Call it DiaGrid and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid. &lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American circus showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog with the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working. The user has scrolled down and over to the right before this screenshot was taken.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridRunning.png]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9221</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9221"/>
		<updated>2017-01-17T02:16:47Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
&lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process, and it is but a work in progress. At present, it shows how to create a grid with scroll bars with wxSmith and how to display it from a running program with the click of a button. But so far, the grid is all blank; putting data into it and getting that data displayed properly is the next step.  &lt;br /&gt;
&lt;br /&gt;
Create a new wxWidgets application. Call it DiaGrid  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid. &lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to show a grid that shows data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; uncheck the Default size box and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. Because we have used “ShowModal”, the program does not get to the “delete” line until the user has closed the dialog with the grid. But because we then promptly “delete” the instance of Barnum – that is to say, we release the space in memory which the “new” command grabbed for it – we should not experience any memory leaks.&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear. You should be able to drag the edges or corners of the grid to enlarge it, and the scroll bars should work. Here is a picture of it working.&lt;br /&gt;
&lt;br /&gt;
[[File:DiaGridRunning.png]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9220</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9220"/>
		<updated>2017-01-17T02:11:16Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process, and it is but a work in progress. At present, it shows how to create a grid with scroll bars with wxSmith and how to display it from a running program with the click of a button. But so far, the grid is all blank; putting data into it and getting that data displayed properly is the next step. &lt;br /&gt;
 &lt;br /&gt;
Create a new wxWidgets application. Call it DiaGrid  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid.&lt;br /&gt;
 &lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to show a grid that shows data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; uncheck the Default size box and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
(The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is.)&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the   grid should appear and the scrollbars should work. You should be able to drag the edges or corners of the grid to enlarge it.&lt;br /&gt;
[[File:MatGridRunning.png]]&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9219</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9219"/>
		<updated>2017-01-17T01:49:32Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
&lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is the distilled result of such a trial-and-error process, and it is but a work in progress. At present, it shows how to create a grid with scroll bars with wxSmith and how to display it from a running program with the click of a button. But so far, the grid is all blank; putting data into it and getting that data displayed properly is the next step.&lt;br /&gt;
  &lt;br /&gt;
Create a new wxWidgets application. Call it DiaGrid  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. For ease in avoiding memory leaks, we will use a Dialog, hence the name DiaGrid. &lt;br /&gt;
&lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxDialog”. Call it Barnum. (Why Barnum? I first used names with “grid” and “dialog” but wxSmith also uses “dialog” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a master American showman; since we are trying to ''show'' a grid that ''shows''' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right. &lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 40 and number of rows to 40; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
If you click the “Show preview” button over on the right (just under the big red X) a grid appears and you can scroll around in it. It is pretty small, but if you try to stretch it with the mouse, you will find that it won't stretch. We have forgotten something. Click on that wxDialog just under Barnum in the Resources pane. Click on the + in the square next to “Style” in is properties box. Scroll down until you get to wxRESIZE-BORDER and check it. Do the same with the wxDialog above Barnum. Now the grid should stretch.&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the editor area of Code::Blocks click on the DiaGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
&lt;br /&gt;
You are thrown into DiaGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void DiaGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;ShowModal();&lt;br /&gt;
   delete pt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of the created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is. The ShowModal call means that the program does not go to the next line until the user closes the window. When that happens, it goes onto the next line and releases the memory grabbed by the &amp;quot;new&amp;quot; command just above.  &lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of DiaGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear and the scrollbars should work. You should be able to drag the edges or corners of the grid to enlarge it.The button on the grid should look something like this.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9218</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9218"/>
		<updated>2017-01-16T03:56:13Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
&lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is a work in progress. At present, it shows how to create a grid with scroll bars with wxSmith and how to display it from a running program with the click of a button. But so far, the grid is all blank; putting data into it and getting that data displayed properly is the next step.&lt;br /&gt;
  &lt;br /&gt;
Create a new wxWidgets application. Call it GridFrame  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. I have not been able to make all the scrolling work  properly with a Dialog, so we will use a Frame.&lt;br /&gt;
 &lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxFrame”. Call it Barnum. (Why Barnum? I first used names with “grid” and “frame” but wxSmith also uses “frame” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to ''show'' a grid to ''show'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it, put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Tutorial10-1.png]]&lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 20 and number of rows to 30; '''uncheck the &amp;quot;Default size&amp;quot; box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to uncheck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the Editor area of Code::Blocks click on the MatGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
You are thrown into MatGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;Show();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of the created instance is arbitrary; it's just old P.T. Barnum's initials. Everything else has to be just as it is.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of MatGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear and the scrollbars should work. You should be able to drag the edges or corners of the grid to enlarge it.&lt;br /&gt;
&lt;br /&gt;
The picture below shows the little &amp;quot;main&amp;quot; window on the left window with the &amp;quot;Show Grid&amp;quot; button. The button has been clicked, the grid displayed, and the scroll bars -- the orange lines on the bottom and right side -- used to move to the right and down in the grid. Notice that the left border column and top border row remain visible while scrolling around in the grid. You can, by the way, click the button again and again. Each time you click, another grid appears on the screen.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9217</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9217"/>
		<updated>2017-01-16T03:51:51Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
&lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is a work in progress. At present, it shows how to create a grid with scroll bars with wxSmith and how to display it from a running program with the click of a button. But so far, the grid is all blank; putting data into it and getting that data displayed properly is the next step.&lt;br /&gt;
  &lt;br /&gt;
Create a new wxWidgets application. Call it GridFrame  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. I have not been able to make all the scrolling work  properly with a Dialog, so we will use a Frame.&lt;br /&gt;
 &lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxFrame”. Call it Barnum. (Why Barnum? I first used names with “grid” and “frame” but wxSmith also uses “frame” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to ''show'' a grid to ''show'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it, put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Tutorial10-1.png]]&lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 20 and number of rows to 30; '''uncheck the &amp;quot;Default size&amp;quot; box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to uncheck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the Editor area of Code::Blocks click on the MatGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
You are thrown into MatGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;Show();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of the created instance is arbitrary; it's just old P.T. Barnum's initials. Everything else has to be just as it is.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of MatGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear and the scrollbars should work. You should be able to drag the edges or corners of the grid to enlarge it.&lt;br /&gt;
&lt;br /&gt;
The picture below shows the little &amp;quot;main&amp;quot; window on the left window with the &amp;quot;Show Grid&amp;quot; button. The button has been clicked, the grid displayed, and the scroll bars -- the orange lines on the bottom and right side -- used to move to the right and down in the grid. Notice that the left border column and top border row remain visible while scrolling around in the grid. You can, by the way, click the button again and again. Each time you click, a another grid appears on the screen.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9216</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9216"/>
		<updated>2017-01-16T03:15:35Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
&lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is a work in progress. At present, it shows how to create a grid with scroll bars with wxSmith and how to display it from a running program with the click of a button. But so far, the grid is all blank; putting data into it and getting that data displayed properly is the next step.&lt;br /&gt;
  &lt;br /&gt;
Create a new wxWidgets application. Call it GridFrame  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. I have not been able to make all the scrolling work  properly with a Dialog, so we will use a Frame.&lt;br /&gt;
 &lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxFrame”. Call it Barnum. (Why Barnum? I first used names with “grid” and “frame” but wxSmith also uses “frame” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to ''show'' a grid to ''show'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it, put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Tutorial10-1.png]]&lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 20 and number of rows to 30; '''uncheck the &amp;quot;Default size&amp;quot; box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to uncheck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the Editor area of Code::Blocks click on the MatGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
You are thrown into MatGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;Show();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; it's just old P.T. Barnum's initials. Everything else has to be just as it is.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of MatGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear and the scrollbars should work. You should be able to drag the edges or corners of the grid to enlarge it.&lt;br /&gt;
&lt;br /&gt;
The picture below shows the little &amp;quot;main&amp;quot; window on the left window with the &amp;quot;Show Grid&amp;quot; button. The button has been clicked, the grid displayed, and the scroll bars -- the orange lines on the bottom and right side -- used to move to the right and down in the grid. Notice that the left border column and top border row remain visible while scrolling around in the grid. You can, by the way, click the button again and again. Each time you click, a another grid appears on the screen.&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9215</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9215"/>
		<updated>2017-01-16T03:06:28Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
&lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is a work in progress. At present, it shows how to create a grid with scroll bars with wxSmith and how to display it from a running program with the click of a button. But so far, the grid is all blank; putting data into it and getting that data displayed properly is the next step.&lt;br /&gt;
  &lt;br /&gt;
Create a new wxWidgets application. Call it GridFrame  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. I have not been able to make all the scrolling work  properly with a Dialog, so we will use a Frame.&lt;br /&gt;
 &lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxFrame”. Call it Barnum. (Why Barnum? I first used names with “grid” and “frame” but wxSmith also uses “frame” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to ''show'' a grid to ''show'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it, put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Tutorial10-1.png]]&lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 20 and number of rows to 30; '''uncheck the &amp;quot;Default size&amp;quot; box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to uncheck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the Editor area of Code::Blocks click on the MatGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
You are thrown into MatGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;Show();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; it's just old P.T. Barnum's initials. Everything else has to be just as it is.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of MatGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear and the scrollbars should work. You should be able to drag the edges or corners of the grid to enlarge it.&lt;br /&gt;
&lt;br /&gt;
The picture below shows the little &amp;quot;main&amp;quot; window on the left window with the &amp;quot;Show Grid&amp;quot; button. The button has been clicked, the grid displayed, and the scroll bars -- the orange lines on the bottom and right side -- used to move to the right and down in the grid. Notice that the left border column and top border row remain visible while scrolling around in the grid. &lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png]]&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9214</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9214"/>
		<updated>2017-01-16T01:57:23Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is a work in progress. At present, it shows how to create a grid with scroll bars with wxSmith and how to display it from a running program with the click of a button. But so far, the grid is all blank; putting data into it and getting that data displayed properly is the next step.&lt;br /&gt;
  &lt;br /&gt;
Create a new wxWidgets application. Call it GridFrame  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. I have not been able to make all the scrolling work  properly with a Dialog, so we will use a Frame.&lt;br /&gt;
 &lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxFrame”. Call it Barnum. (Why Barnum? I first used names with “grid” and “frame” but wxSmith also uses “frame” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to ''show'' a grid to ''show'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it, put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Tutorial10-1.png]]&lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 20 and number of rows to 30; '''uncheck the &amp;quot;Default size&amp;quot; box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to uncheck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the Editor area of Code::Blocks click on the MatGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
You are thrown into MatGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;Show();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; it's just old P.T. Barnum's initials. Everything else has to be just as it is.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of MatGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear and the scrollbars should work. You should be able to drag the edges or corners of the grid to enlarge it.&lt;br /&gt;
&lt;br /&gt;
The picture below shows little &amp;quot;main&amp;quot; window on the left window on the lef&lt;br /&gt;
&lt;br /&gt;
[[File:MatGridRunning.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=File:MatGridRunning.png&amp;diff=9213</id>
		<title>File:MatGridRunning.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=File:MatGridRunning.png&amp;diff=9213"/>
		<updated>2017-01-16T01:51:04Z</updated>

		<summary type="html">&lt;p&gt;Grouch: Grouch uploaded a new version of File:MatGridRunning.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For wxSmith Tutorial 10 blank grid running.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9212</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9212"/>
		<updated>2017-01-16T01:13:09Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is a work in progress. At present, it shows how to create a grid with scroll bars with wxSmith and how to display it from a running program with the click of a button. But so far, the grid is all blank; putting data into it and getting that data displayed properly is the next step.&lt;br /&gt;
  &lt;br /&gt;
Create a new wxWidgets application. Call it GridFrame  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. I have not been able to make all the scrolling work  properly with a Dialog, so we will use a Frame.&lt;br /&gt;
 &lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxFrame”. Call it Barnum. (Why Barnum? I first used names with “grid” and “frame” but wxSmith also uses “frame” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to ''show'' a grid to ''show'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it, put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Tutorial10-1.png]]&lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 20 and number of rows to 30; '''uncheck the &amp;quot;Default size&amp;quot; box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to uncheck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the Editor area of Code::Blocks click on the MatGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
You are thrown into MatGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;Show();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; it's just old P.T. Barnum's initials. Everything else has to be just as it is.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of MatGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear and the scrollbars should work. You should be able to drag the edges or corners of the grid to enlarge it.&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=File:MatGridRunning.png&amp;diff=9211</id>
		<title>File:MatGridRunning.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=File:MatGridRunning.png&amp;diff=9211"/>
		<updated>2017-01-16T00:59:32Z</updated>

		<summary type="html">&lt;p&gt;Grouch: For wxSmith Tutorial 10 blank grid running.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;For wxSmith Tutorial 10 blank grid running.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9210</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9210"/>
		<updated>2017-01-16T00:18:10Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is a work in progress. At present, it shows how to create a grid with scroll bars with wxSmith and how to display it from a running program with the click of a button. But so far, the grid is all blank; putting data into it and getting that data displayed properly is the next step.&lt;br /&gt;
  &lt;br /&gt;
Create a new wxWidgets application. Call it GridFrame  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. I have not been able to make all the scrolling work  properly with a Dialog, so we will use a Frame.&lt;br /&gt;
 &lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxFrame”. Call it Barnum. (Why Barnum? I first used names with “grid” and “frame” but wxSmith also uses “frame” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to ''show'' a grid to ''show'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it, put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Tutorial10-1.png]]&lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 20 and number of rows to 30; '''uncheck the &amp;quot;Default size&amp;quot; box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to uncheck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the Editor area of Code::Blocks click on the MatGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
You are thrown into MatGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;Show();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; it's just old P.T. Barnum's initials. Everything else has to be just as it is.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of MatGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear and the scrollbars should work. You should be able to drag the edges or corners of the grid to enlarge it.&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9209</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9209"/>
		<updated>2017-01-16T00:04:26Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is a work in progress. At present, it shows how to create a grid with scroll bars with wxSmith and how to display it from a running program with the click of a button. But so far, the grid is all blank; putting data into it and getting that data displayed properly is the next step.&lt;br /&gt;
  &lt;br /&gt;
Create a new wxWidgets application. Call it GridFrame  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. I have not been able to make all the scrolling work  properly with a Dialog, so we will use a Frame.&lt;br /&gt;
 &lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxFrame”. Call it Barnum. (Why Barnum? I first used names with “grid” and “frame” but wxSmith also uses “frame” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to ''show'' a grid to ''show'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it, put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Tutorial10-1.png]]&lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 20 and number of rows to 30; '''uncheck the Default size box''' and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the Editor area of Code::Blocks click on the MatGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
You are thrown into MatGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;Show();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; it's just old P.T. Barnum's initials. Everything else has to be just as it is.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of MatGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear and the scrollbars should work. You should be able to drag the edges or corners of the grid to enlarge it.&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=File:Tutorial10-1.png&amp;diff=9208</id>
		<title>File:Tutorial10-1.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=File:Tutorial10-1.png&amp;diff=9208"/>
		<updated>2017-01-15T23:31:31Z</updated>

		<summary type="html">&lt;p&gt;Grouch: Shows bottom of Resources pane while creating Tutorial 10.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Shows bottom of Resources pane while creating Tutorial 10.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=WxSmith_tutorials&amp;diff=9207</id>
		<title>WxSmith tutorials</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=WxSmith_tutorials&amp;diff=9207"/>
		<updated>2017-01-15T17:08:53Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
Welcome to the wxSmith tutorials page! wxSmith combines with Code::Blocks, wxWidgets and a C++ compiler to give you a  WYSIWYG way to create applications with a graphical user interface (GUI). The combination forms a tool for Rapid Application Development (RAD) that works on Linux, Mac OS X and Windows. As you work, you see on the screen the forms you are designing; and they look to you just like they will look to the user of your program. &lt;br /&gt;
&lt;br /&gt;
The tutorials assume no prior knowledge of Code::Blocks or wxWidgets and are, in fact, good tutorials for learning them also. They do assume a basic acquaintance with C++ to recognize what you are looking at in code snippets that form part of the tutorials. &lt;br /&gt;
&lt;br /&gt;
Moreover, wxSmith knows a lot about all the major wxWidgets components – buttons,  check boxes, radio buttons, drop-down lists and so on. When you have selected and “dropped” one onto your form, the wxSmith property browser shows you all the component's properties and lets you modify them. It can also show all the events a component can produce and, on a quick mouse click, will set up the framework for you to code your program's response to the event. &lt;br /&gt;
&lt;br /&gt;
Although wxSmith is strictly speaking a plugin to Code::Blocks, that fact is a technicality important only to writers of the program. The user, however, downloads, installs, and uses one program. Linux users installing from the Ubuntu Software Center, however, should be sure to check the boxes next to all of the &amp;quot;Optional add-ons.&amp;quot; As a user, it will look to you like wxSmith is just a part of Code:Blocks.  &lt;br /&gt;
&lt;br /&gt;
Our tutorials will start from the very basics and work up to some fairly tricky but very useful techniques.  &lt;br /&gt;
&lt;br /&gt;
Before you can use wxSmith, however, you need to install several libraries. If you are using Ubuntu Linux or one of its derivatives, you can install them from the Ubuntu Software Center. The libraries you need are:&lt;br /&gt;
&lt;br /&gt;
libwxgtk2.8-dev (for compiling)&lt;br /&gt;
&lt;br /&gt;
libwxgtk2.8-0   (the runtime library)&lt;br /&gt;
&lt;br /&gt;
libwxgtk2.8-dbg   (for debugging).&lt;br /&gt;
&lt;br /&gt;
[If you know how to get this material from other sources, please edit this to share that knowledge.]&lt;br /&gt;
&lt;br /&gt;
Here is a list of the tutorials. You may click on one to jump to it, but they are definitely cumulative, and you should work through them in order.&lt;br /&gt;
&lt;br /&gt;
* Tutorial 1: [[wxSmith tutorial: Hello world|Hello world]]&lt;br /&gt;
* Tutorial 2: [[wxsmith tutorial: Working with items|Working with Menus and Components]]&lt;br /&gt;
* Tutorial 3: [[wxSmith tutorial: Building more complex window|Building a More Complex Window]]&lt;br /&gt;
* Tutorial 4: [[wxSmith tutorial: Working with multiple resources|Working with Multiple Forms]]&lt;br /&gt;
* Tutorial 5: [[wxSmith tutorial: Using wxPanel resources|Using wxPanel resources]]&lt;br /&gt;
* Tutorial 6: [[wxSmith tutorial: Accessing items in resource|Accessing Components in a Form]]&lt;br /&gt;
* Tutorial 7: [[wxSmith tutorial: Creating items with custom paint and mouse handling|Creating items with custom paint and mouse handling]]&lt;br /&gt;
* Tutorial 8: [[wxSmith tutorial: Drawing on the Screen and Saving Drawings|Drawing on the Screen and Saving Drawings]]&lt;br /&gt;
* Tutorial 9: [[wxSmith tutorial: Keyboard Input and Displaying Results|Keyboard Input and Displaying Results]] &lt;br /&gt;
* Tutorial 10: [[Using wxGrid]]:  Creating a wxGrid with wxSmith&lt;br /&gt;
* See also: [[wxSmith extensions]]&lt;br /&gt;
&lt;br /&gt;
The book ''The Gwx Story'' recounts in detail writing a program for linear regression and model building using wxSmith and CodeBlocks. Some of the tutorials evolved in the course of writing this book. It is available inexpensively from Amazon and should prove helpful to anyone trying to learn the use of these tools.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9206</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9206"/>
		<updated>2017-01-15T09:10:18Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:wxSmith Documentation]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is a work in progress. At present, it shows how to create a grid with scroll bars with wxSmith and how to display it from a running program with the click of a button. But so far, the grid is all blank; putting data into it and getting that data displayed properly is the next step.&lt;br /&gt;
  &lt;br /&gt;
Create a new wxWidgets application. Call it GridFrame  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. I have not been able to make all the scrolling work  properly with a Dialog, so we will use a Frame.&lt;br /&gt;
 &lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxFrame”. Call it Barnum. (Why Barnum? I first used names with “grid” and “frame” but wxSmith also uses “frame” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it, put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown on the right. (Figure will come.)&lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 20 and number of rows to 30; uncheck the Default size box and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the Editor area of Code::Blocks click on the MatGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
You are thrown into MatGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;Show();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; it's just old P.T. Barnum's initials. Everything else has to be just as it is.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of MatGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear and the scrollbars should work. You should be able to drag the edges or corners of the grid to enlarge it.&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9205</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9205"/>
		<updated>2017-01-15T08:57:10Z</updated>

		<summary type="html">&lt;p&gt;Grouch: /* Tutorial 10. Using wxGrid */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:wxSmith Documentation]]&lt;br /&gt;
''Italic text''=Tutorial 10. Using wxGrid=&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is a work in progress. At present, it shows how to create a grid with scroll bars with wxSmith and how to display it from a running program with the click of a button. But so far, the grid is all blank; putting data into it and getting that data displayed properly is the next step.&lt;br /&gt;
  &lt;br /&gt;
Create a new wxWidgets application. Call it GridFrame  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. I have not been able to make all the scrolling work  properly with a Dialog, so we will use a Frame.&lt;br /&gt;
 &lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxFrame”. Call it Barnum. (Why Barnum? I first used names with “grid” and “frame” but wxSmith also uses “frame” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to ''show'' a grid that ''shows'' data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it, put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown on the right. (Figure will come.)&lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 20 and number of rows to 30; uncheck the Default size box and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the Editor area of Code::Blocks click on the MatGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
You are thrown into MatGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;Show();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; it's just old P.T. Barnum's initials. Everything else has to be just as it is.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of MatGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear and the scrollbars should work. You should be able to drag the edges or corners of the grid to enlarge it.&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9204</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9204"/>
		<updated>2017-01-15T08:41:10Z</updated>

		<summary type="html">&lt;p&gt;Grouch: /* Tutorial 10. Using wxGrid */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:wxSmith Documentation]]&lt;br /&gt;
=Tutorial 10. Using wxGrid=&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is a work in progress. At present, it shows how to create a grid with scroll bars with wxSmith and how to display it from a running program with the click of a button. But so far, the grid is all blank; putting data into it and getting that data displayed properly is the next step.&lt;br /&gt;
  &lt;br /&gt;
Create a new wxWidgets application. Call it GridFrame  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. I have not been able to make all the scrolling work  properly with a Dialog, so we will use a Frame.&lt;br /&gt;
 &lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxFrame”. Call it Barnum. (Why Barnum? I first used names with “grid” and “frame” but wxSmith also uses “frame” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to show a grid that shows data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it, put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown on the right. (Figure will come.)&lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 20 and number of rows to 30; uncheck the Default size box and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on the + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with it the grid. So in the Editor area of Code::Blocks click on the MatGridframe.wxs tab. Drop onto it a box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
You are thrown into MatGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;Show();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of MatGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear and the scrollbars should work. You should be able to drag the edges or corners of the grid to enlarge it.&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9203</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9203"/>
		<updated>2017-01-15T08:27:45Z</updated>

		<summary type="html">&lt;p&gt;Grouch: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:wxSmith Documentation]]&lt;br /&gt;
=Tutorial 10. Using wxGrid=&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is a work in progress. At present, it shows how to create a grid with scroll bars with wxSmith and how to display it from a running program with the click of a button. But so far, the grid is all blank; putting data into it and getting that data displayed properly is the next step.&lt;br /&gt;
  &lt;br /&gt;
Create a new wxWidgets application. Call it GridFrame  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. I have not been able to make all the scrolling work  properly with a Dialog, so we will use a Frame.&lt;br /&gt;
 &lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxFrame”. Call it Barnum. (Why Barnum? I first used names with “grid” and “frame” but wxSmith also uses “frame” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to show a grid that shows data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith. The lower part of the Management pane should now look as shown on the right.&lt;br /&gt;
&lt;br /&gt;
Click on the wxGrid and set its number of columns to 20 and number of rows to 30; uncheck the Default size box and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
 Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with the grid. So in the editor area of Code::Blocks click on the MatGridframe.wxs tab. Drop onto it box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
You are thrown into MatGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;Show();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is.&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of MatGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the grid should appear and the scrollbars should work. You should be able to drag the edges or corners of the grid to enlarge it.&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
	<entry>
		<id>https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9202</id>
		<title>Using wxGrid</title>
		<link rel="alternate" type="text/html" href="https://wiki.codeblocks.org/index.php?title=Using_wxGrid&amp;diff=9202"/>
		<updated>2017-01-15T07:46:01Z</updated>

		<summary type="html">&lt;p&gt;Grouch: Comprehensive revision by the original author to show  the grid from a button click rather than at all times.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:wxSmith Documentation]]&lt;br /&gt;
=Tutorial 10. Using wxGrid=&lt;br /&gt;
&lt;br /&gt;
A grid can be a useful way to display data, especially matrices of numbers. If the matrices are large, the full grid will be too big for the screen, so we will want to display it in modest proportions but allow the user to resize it or scroll about in it with the mouse. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like so many things related to computing, creating such a grid with wxSmith is easy once you know how, but figuring out how can consume many hours. What follows is a work in progress. At present, it shows how to create a grid with scroll bars with wxSmith and how to display it from a running program with the click of a button. But so far, the grid is all blank; putting data into it and getting that data displayed properly is the next step.&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
Create a new wxWidgets application. Call it GridFrame  and make it frame-based. We don't want the grid showing all the time, only when we call it up. So we need to add a Frame or Dialog as we did back in Tutorial 4. I have not been able to make all the scrolling work  properly with a Dialog, so we will use a Frame.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Click on the wxSmith tab of the CodeBlocks main menu and click “Add wxFrame”. Call it Barnum. (Why Barnum? I first used names with “grid” and “frame” but wxSmith also uses “frame” a lot and “grid” has a specific meaning. The names became very confusing; something unique was needed. P.T. Barnum was a famous American showman; since we are trying to show a grid that shows data, “Barnum” seemed as good choice as any.) Drop a box sizer into the frame. Into the sizer put a panel and check the panel's Expand property. Onto the panel drop another box sizer. Into it put a wxGrid from the “Advanced” tab of wxSmith.  The lower part of the Management pane should now look as shown on the right.&lt;br /&gt;
 &lt;br /&gt;
Click on the wxGrid and set its number of columns to 20 and number of rows to 30; uncheck the Default size box and set the width to 400 and height to 300. (These numbers are in pixels. It is very important to unckeck that Default size box.) Click on + inside a □ next to the word Style to drop down a list of Style features; check the box for wxFullRepaintOnResize. Finally, check the Expand box. At this point you should see encouraging signs on the right; a grid has appeared. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now that we have a grid in our frame, we need a way to show it from the running program. The simplest way is to have a button which, when clicked, will show the frame and with the grid. So in the editor area of Code::Blocks click on the MatGridframe.wxs tab. Drop onto it box sizer and into the box sizer a panel, and onto the panel a button. Change the button's label to “ShowGrid” and double click the button. &lt;br /&gt;
You are thrown into MatGridMain.cpp. Down at the bottom of the file you will find that an empty frame has been created for you to specify what to do when that button is clicked. The frame looks like this:&lt;br /&gt;
&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
And you fill it in to look like this:&lt;br /&gt;
&lt;br /&gt;
void MatGridFrame::OnButton1Click(wxCommandEvent&amp;amp; event)&lt;br /&gt;
{&lt;br /&gt;
   Barnum *pt = new Barnum(this);&lt;br /&gt;
   pt-&amp;gt;Show();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
(The choice of pt as the name of created instance is arbitrary; the letters are just old Barnum's initials. Everything else has to be just as it is.)&lt;br /&gt;
&lt;br /&gt;
There is one more thing that must be done before the program will compile. wxSmith created a header file to go with Barnum but it did not “include” it in the main program. We must do so.  Run the scrollbar up to the top of MatGridMain.cpp. The first non-comment lines you see are these:&lt;br /&gt;
&lt;br /&gt;
	#include &amp;quot;wx_pch.h&amp;quot;&lt;br /&gt;
	#include &amp;quot;MatGridMain.h&amp;quot;&lt;br /&gt;
	#include &amp;lt;wx/msgdlg.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Just below them add:&lt;br /&gt;
	#include &amp;quot;Barnum.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Now click the Code::Blocks “Build and run” button. The code should compile, link and begin executing. But only a small frame with a button labeled “Show Grid” appears. Click the button, and the   grid should appear and the scrollbars should work. You should be able to drag the edges or corners of the grid to enlarge it.&lt;br /&gt;
&lt;br /&gt;
Of course, there is nothing in the grid. That comes next.&lt;/div&gt;</summary>
		<author><name>Grouch</name></author>
	</entry>
</feed>