Using the Flexgrid in VC++
2008-04-23 22:36
302 查看
Introduction
When I had to use the flexgrid for the first time, I was too frustrated to find out that no proper documentation existed on the net. The ones available were too complicated for me to understand. And the ones that were easy were in VB. This article is to help persons who are going to use the flexgrid in their applications using VC++. Also take a look at the Warning note at the end of this article.Implementation
Step 1
First, include the msflexgrid control in the project. To do that :-In the VC++ IDE Menu, go to Project->Add To Project->Components and Controls menu.
Then , in the dialog box that appears, select Registered ActiveX Controls. There, You can see a control named "Microsoft Hierarchical FlexGrid Control...".
Select that and add it to your project using the Insert button. You can now see the FlexGrid control in the resource editor's CONTROLS toolbar.
Add it to your dialog as you add a control usually.
Step 2
Then, set the properties as you want it to be. Right click on the grid and select the Properties option. Change the settings there as per your requirements.Step 3
Add a member variable for that grid. E.g.m_Grid. The sample given below is for an example. Use it as a guideline to make your application.
Step 4
Its better to clear the flexgrid before you do any operations on it. To do that, use :-m_Grid.Clear();
Step 5
To add records to the Grid, use something like this.CString strName,strRemarks; m_nCount = 0; // Clear and refresh the grid m_Grid.Clear(); m_Grid.Refresh(); // Get the value for strName from the database here // Get the strRemarks from the database here m_nCols = m_Grid.GetCols(); m_Grid.SetTextArray(0, "Name " ); // First Column m_Grid.SetTextArray(1, "Remarks " ); // Second Column m_nCount++; // Fill First Column m_Grid.SetTextArray( m_nCols * m_nCount + 0,strName ); // Fill Second Column m_Grid.SetTextArray( m_nCols * m_nCount + 1, strRemarks ); // Redraw the grid m_Grid.SetRedraw(TRUE); m_Grid.Refresh();
Step 6
To retrieve data from the Grid when the user double clicks on a record, add a double click message handler for the grid using the class wizard. Assuming that you have named the function asOnDblClickGrid, then :-
void YourDialog::OnDblClickGrid() { // Get the current row and column int nRow = m_Grid.GetRow(); int nCol = m_Grid.GetCol(); CString strName,strRemarks; // Get data from the First Column strName = m_Grid.GetTextMatrix(nRow,nCol+0); // Get data from the Second Column strRemarks = m_Grid.GetTextMatrix(nRow,nCol+1); }
Step 7
To move to the previous record, do this :-Collapse
void YourDialog::OnBtnPrevious() { m_Grid.SetRedraw(FALSE); // Get the current selection int NextRow = m_Grid.GetRowSel(); // If the position is at the last record, return if(NextRow <= 1) { return; } else { long BackColor[2],FontColor[2]; int Column; // The BackColor and the FontColor variables // are manipulated because we want a // selected effect to be given to the previous // record. Here, we are merely changing // the color of the selected // row to give it that effect. BackColor[0] = 0x00FFFFFF; BackColor[1] = 0x00FFFFB0; FontColor[0] = 0x00400000; FontColor[1] = 0x000000FF; for(Column = 1; Column < m_Grid.GetCols(); Column++) { m_Grid.SetCol(Column); m_Grid.SetCellBackColor(BackColor[0]); m_Grid.SetCellForeColor(FontColor[0]); } m_Grid.SetRow(--NextRow); for(Column = 1; Column < m_Grid.GetCols(); Column++) { m_Grid.SetCol(Column); m_Grid.SetCellBackColor(BackColor[1]); m_Grid.SetCellForeColor(FontColor[1]); } m_Grid.Refresh(); m_Grid.SetRedraw(TRUE); } }
Step 8
To got to the Next record, do the reverse of the code above. Instead ofm_Grid.SetRow(--NextRow)it would be
m_Grid.SetRow(++NextRow).
Warning
Whenever you use a flexgrid in your application, you have to be twice as careful. Be sure to take regular backups. Sometimes, you might note that your compilation time is too longer than usual. It would be more and more slow with each build. If you feel so, check the size of your .rc file. If its size is abnormal ( I cant specify a size because it depends on your project and its resource contents ),then delete the flexgrid from your application , Close Visual Studio and copy the .rc file from your backup. Open your project again. That should solve your problem. I'm not sure why this happens, maybe its a bug in flexgrid that corrupts or damages it. But from your side, be careful.Conclusion
The flexgrid is a very easy control to use. But whenever you use it , repeat the mantra "take backups of your .rc file regularly" until it becomes a habit. That's it. All luck and have a great time.相关文章推荐
- How to enumerate the system fonts in the combobox control using VC++ - 用VC++如何在ComboBox控件中枚举系统字体
- Showing the Image file thumbnail view in ListView control using VC++ 6.0
- Notes about <VC3: Trustworthy Data Analytics in the Cloud using SGX>
- [ReactVR] Render Custom 3D Objects Using the Model Component in React VR
- Maven出现以下问题:The Maven Integration requires that Eclipse be running in a JDK, because a number of Maven core plugins are using ja
- 打开一个VC工程提示"Not all of the windows in the workspace could be opened."
- The Essentials for Using COM in Managed Code
- Using the sed editor in Linux - from Oracle Tech Network
- 第五天(Using the Data Package in Sencha Touch)
- Using the Data Package in Sencha Touch
- Using the Java UNO runtime and API in your IDE
- 使用cocapods报错 [!] Your Podfile has had smart quotes sanitised. To avoid issues in the future, you should not use TextEdit for editing it. If you are not using TextEdit, you should turn off smart quotes
- Reining in the Outliers in Map-Reduce Clusters using Mantri
- [Javascript] Identify the most important words in a document using tf-idf in Natural
- Using the ASP.NET 2.0 ReportViewer in Local Mode
- 转载:Using PowerShell in the build process 使用Powershell进行build
- mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication解决办法
- [RT] Twitter from the command line in python using OAuth
- Warning: Using a password on the command line interface can be insecure
- Using the five elements of fashion colors to create the best feng shui in auspicious Home