Representation of data is one the central aspects of any application. Tabular representation of data is the most common method of representing given data. Each language/framework provides its own technique, in the form of controls, to present data in tabular format. MFC (Microsoft Foundation Classes) is no exception. One of the controls that it provides is the MSFlexGrid control.
Programming MSFlexGrid in MFC (VC++) - MSFlexGrid in the Real World (Page 3 of 4 )
The application that is going to be developed is based on an example provided by Miss Sormita Chakraborty. The application will take user input and save the input data. The application components will include an SDI window and a dialog that contains the MSFlexGrid. So let's get started.
The first step is to create an SDI-based application. Then we will add a dialog to the application. Since these are common steps, I will not elaborate on them here. After taking these steps, we will add an MSFlexGrid component by using Components and the controls dialog box. Next, we add a variable for representing the grid control. Let's name it m_edit.
Then add the following code in the function for the KeyPressed event:
The code checks to see whether the key pressed has a value of 13. If not, it is saved in a string variable named str. Then it sets the value in the grid. Next, the data retrieved needs to be saved. For that, two arrays are declared in the class that provides the edit functionality for the grid, which is named CEditGrid. The following are the statements:
// virtual void GetInput(CString buf);
virtual void CEditGrid::GetTextGrid();
//other parts not shown for brevity
Once that is done, the values are taken from the grid. The following method contains the logic
This method is called from the onUpdateGrid method of the EditGrid class.