谁有使用MSFlexGrid控件的代码?
发到我的邮箱也可以,[email protected]

解决方案 »

  1.   

    Step 1 :-  First, include the msflexgrid control in the project. To add that control,     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 Hierarchial 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.Step 2 :- Then, set the properties as you want it to be. Right click on the grid and select
      the Properties option. Then change the settings as you like.Step 3 :- Add a member variable for that grid. Ex. 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,strRes;  m_nCount = 0;

     m_Grid.Clear();
     m_Grid.Refresh(); // Get the value for strName from the database here 
    // Get the strRes from the database here  m_nCols = m_Grid.GetCols();
     m_Grid.SetTextArray(0, "Name " ); // First  Column
     m_Grid.SetTextArray(1, "Res " ); // Second  Column  m_nCount++;  m_Grid.SetTextArray(  m_nCols * m_nCount + 0,strName ); // Fill First Column 
     m_Grid.SetTextArray(  m_nCols * m_nCount + 1, strRes ); // Fill Second  Column  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 as OnDblClickGrid, then void YourDialog::OnDblClickGrid()
    {
     int nRow = m_Grid.GetRow();
     int nCol = m_Grid.GetCol();  CString strName,strRes;  strName    =  m_Grid.GetTextMatrix(nRow,nCol+0); // Get data from the First Column
     strRes =  m_Grid.GetTextMatrix(nRow,nCol+1); // Get data from the Second Column
    }Step 7 :-  To move to the previous record void YourDialog::OnBtnPrevious()
    {
     m_Grid.SetRedraw(FALSE);  int NextRow = m_Grid.GetRowSel();  if(NextRow <=1)
     {
    return; // At last record
     }
     else
       {
    long BackColor[2],FontColor[2];  int Column;

    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 of m_Grid.SetRow(--NextRow) it would be
     m_Grid.SetRow(++NextRow). Thats it. All luck and have a great time.