• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            xbgs

            C++博客 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
              7 Posts :: 0 Stories :: 13 Comments :: 0 Trackbacks

            ?在單文檔中的使用方法
            步驟一 初始化

            在CView類(lèi)的.h頭文件中包含文件:
            ??? #include "Gridctrl.h"

            并且手寫(xiě)加入如下的成員函數(shù):
            ????CGridCtrl * m_pGridCtrl;

            步驟二 構(gòu)造與析構(gòu)

            構(gòu)造函數(shù)中:
            ???m_pGridCtrl = NULL;
            析構(gòu)函數(shù)中:
            ???if(m_pGridCtrl)
            ???????delete m_pGridCtrl;


            步驟三 如果需要打印功能的話添加同名打印函數(shù)代碼

            在CView類(lèi)的OnBeginPrinting()函數(shù)中添加如下代碼:
            if(m_pGridCtrl)
            ????m_pGridCtrl->OnBeginPrinting(pDC,pInfo);
            //簡(jiǎn)單吧,這就是類(lèi)的好處

            其它兩個(gè)打印函數(shù)也一樣的做法.

            步驟四 在OnInitaUpdate()函數(shù)中或者你自己添加的要顯示Grid的消息函數(shù)中如下初始化:

               //創(chuàng)建非模式對(duì)話框
            CDlg *dlg;
            dlg=new CDlg();
            dlg->Create(IDD_Dlg,this);

            //初始化GridCtrl控件
            if(m_pGridCtrl!=NULL)
            {
            delete m_pGridCtrl;
            m_pGridCtrl=NULL;
            }
            if (m_pGridCtrl == NULL)
            {
            // Create the Gridctrl object
            m_pGridCtrl = new CGridCtrl;
            if (!m_pGridCtrl) return 0;
            // Create the Gridctrl window
            CRect rect;
            GetClientRect(rect);
            m_pGridCtrl->Create(rect, this, 100);
            // fill it up with stuff
            m_pGridCtrl->SetEditable(false);
            m_pGridCtrl->SetTextBkColor(RGB(0xFF, 0xFF, 0xE0)); //黃色背景
            m_pGridCtrl->EnableDragAndDrop(false);
            try {
            m_pGridCtrl->SetRowCount(k); //設(shè)置行數(shù)為k行
            m_pGridCtrl->SetColumnCount(4); //k列
            m_pGridCtrl->SetFixedRowCount(1); //標(biāo)題行為一行
            m_pGridCtrl->SetFixedColumnCount(1); //同上
            }
            catch (CMemoryException* e)
            {
            e->ReportError();
            e->Delete();
            return 0;
            }
            //填充列標(biāo)題
            int row=0;
            for(int col=0;col<4;col++)
            {
            GV_ITEM Item;
            Item.mask = GVIF_TEXT|GVIF_FORMAT;
            Item.row = row;
            Item.col = col;
            if(col==0){
            Item.nFormat = DT_CENTER|DT_WORDBREAK;
            Item.strText.Format(_T("【類(lèi)別】"),col);
            }
            else if(col==1){
            Item.nFormat = DT_LEFT|DT_WORDBREAK;
            Item.strText.Format(_T("第一列"),col);
            }
            else if(col==2){
            Item.nFormat = DT_LEFT|DT_WORDBREAK;
            Item.strText.Format(_T("第二列"),col);
            }
            m_pGridCtrl->SetItem(&Item);
            }
            // fill rows/cols with text
            for (row = 1; row < k; row++)
            for (col = 0; col < h; col++)
            {
            GV_ITEM Item;
            Item.mask = GVIF_TEXT|GVIF_FORMAT;
            Item.row = row;
            Item.col = col;
            if (col < 1) { //行標(biāo)題頭
            Item.nFormat = DT_CENTER|DT_VCENTER
            |DT_SINGLELINE|DT_END_ELLIPSIS
            |DT_NOPREFIX;
            Item.strText.Format(_T("%d"),row);
            }
            else if(col==1){ //第一列的值
            Item.nFormat = DT_CENTER|DT_VCENTER
            |DT_SINGLELINE|DT_END_ELLIPSIS
            |DT_NOPREFIX;
            str="aa";
            Item.strText.Format(_T("%s"),str);
            }else if(col==2){ //第二列第值
            Item.nFormat = DT_CENTER|DT_VCENTER
            |DT_SINGLELINE|DT_END_ELLIPSIS
            |DT_NOPREFIX;
            CString str;
            str="bb";
            Item.strText.Format(_T("%s"),str);
            }
            m_pGridCtrl->SetItem(&Item);
            }
            m_pGridCtrl->AutoSize();

            //--------------設(shè)置行列距------------------
            for(int a=1;a<m;a++)
            m_pGridCtrl->SetRowHeight(a,21); //設(shè)置各行高
            m_pGridCtrl->SetRowHeight(0,24); //設(shè)置0行高
            m_pGridCtrl->SetColumnWidth(1,110); //設(shè)置2列寬
            m_pGridCtrl->SetColumnWidth(2,160); //設(shè)置3列寬
            m_pGridCtrl->SetColumnWidth(3,100); //設(shè)置4列寬
            }
            上例取自實(shí)際工程,稍有修改!
            部分注釋:
            void SetVirtualMode(TRUE) //設(shè)為虛模式
            BOOL SetRowCount(int nRows) //設(shè)置總的行數(shù)。
            BOOL SetFixedRowCount(int nFixedRows = 1)//設(shè)置固定的行數(shù)據(jù)
            BOOL SetColumnCount(int nCols) //設(shè)置列數(shù)
            BOOL SetFixedColumnCount(int nFixedCols = 1)//設(shè)置固定的列數(shù)


            步驟五: 添加WM_SIZE消息,調(diào)整控件的界面占屏幕大小

            ??if(m_pGridCtrl->GetSafeHWnd())
            ???{
            ??????CRect rect;
            ?????GetClientRect(rect);
            ?????m_pGridCtrl->MoveWindow(rect);
            ???}



            ?在對(duì)話框中的使用方法

            步驟一 創(chuàng)建數(shù)據(jù)顯示表格對(duì)話框

            在資源管理器中新創(chuàng)建一個(gè)對(duì)話框,假設(shè)為CDlgTestReportBox。 從工具箱中加入Custom Control,就是人頭像的那個(gè),將其區(qū)域拉伸至要顯示數(shù)據(jù)表格的大小,充滿整個(gè)對(duì)話框。

            在CDlgTestReportBox類(lèi)的頭文件中:

            #include "GridCtrl.h"

            再定義成員變量:

            CGridCtrl* m_pGrid;

            添加OnShowWindow()消息處理函數(shù)如下:

            void CDlgTestReportBox::OnShowWindow(BOOL bShow, UINT nStatus) 
            {
            CDialog::OnShowWindow(bShow, nStatus);
            // TODO: Add your message handler code here
            if(m_pGrid!=NULL)
            {
            delete m_pGrid;
            m_pGrid=NULL;
            }
            if(m_pGrid==NULL)
            {
            m_pGrid=new CGridCtrl;
            CRect rect;
            GetDlgItem(IDC_ReportAera)->GetWindowRect(rect); //得到顯示區(qū)域
            ScreenToClient(&rect);
            m_pGrid->Create(rect,this,100);
            m_pGrid->SetEditable(false);
            m_pGrid->SetTextBkColor(RGB(0xFF, 0xFF, 0xE0)); //黃色背景
            try
            {
            m_pGrid->SetRowCount(10); //初始為10行
            m_pGrid->SetColumnCount(11); //初始化為11列
            m_pGrid->SetFixedRowCount(1); //表頭為一行
            m_pGrid->SetFixedColumnCount(1); //表頭為一列
            }
            catch (CMemoryException* e)
            {
            e->ReportError();
            e->Delete();
            // return FALSE;
            }
            for (int row = 0; row < m_pGrid->GetRowCount(); row++)
            for (int col = 0; col < m_pGrid->GetColumnCount(); col++)
            {
            //設(shè)置表格顯示屬性
            GV_ITEM Item;
            Item.mask = GVIF_TEXT|GVIF_FORMAT;
            Item.row = row;
            Item.col = col;
            if(row==0&&col==0) //第(0,0)格
            {
            Item.nFormat = DT_CENTER|DT_WORDBREAK;
            Item.szText.Format(_T("報(bào)表顯示"),col);
            }
            else if (row < 1) //設(shè)置0行表頭顯示
            {
            Item.nFormat = DT_CENTER|DT_WORDBREAK;
            Item.szText.Format(_T(" 項(xiàng)目%d"),col);
            }
            else if (col < 1) //設(shè)置0列表頭顯示
            {
            if(row< m_pGrid->GetRowCount()-4)
            {
            Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;
            Item.szText.Format(_T("第%d次"),row);
            }
            }
            else
            {
            Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;
            Item.szText.Format(_T(""),2);
            }
            m_pGrid->SetItem(&Item);
            }
            m_pGrid->Invalidate();
            }
            //--------------設(shè)置行列距------------------
            for(int a=0;aGetRowCount();a++)
            m_pGrid->SetRowHeight(a,16); //設(shè)置各行高
            m_pGrid->SetColumnWidth(0,58); //設(shè)置0列寬
            for(int b=1;bGetColumnCount();b++)
            m_pGrid->SetColumnWidth(b,59); //設(shè)置各列寬
            }

            ?

            步驟二 嵌入上面的對(duì)話框 顯示數(shù)據(jù)

            在你需要顯示數(shù)據(jù)的對(duì)話框上的頭文件中,假設(shè)為CDlgTest,加入

            #include "GridCtrl.h"

            CDlgTestReportBox* m_pTestReportBox;

            將數(shù)據(jù)顯示對(duì)話框放入你的對(duì)話框相應(yīng)位置上,在CDlgTest::OnInitDialog() 中:

            if(!m_pTestReportBox)
            {
            ?????m_pTestReportBox=new CDlgTestReportBox(this);
            }

            m_pTestReportBox->Create(IDD_DlgTestReportBox,this);

            //定義區(qū)域變量
            CRect rectDraw;
            GetDlgItem(IDC_AeraReport)->GetWindowRect(rectDraw);
            ScreenToClient(&rectDraw); //動(dòng)態(tài)測(cè)試數(shù)據(jù)顯示區(qū)域rectDraw

            //將對(duì)應(yīng)的對(duì)話框放到指定區(qū)域
            m_pTestReportBox->MoveWindow(rectDraw);
            m_pTestReportBox->ShowWindow(SW_SHOW);

            自定義填充數(shù)據(jù)的函數(shù):CDlgTest::FillGrid() 如下:

            CGridCtrl* pGrid=m_pTestReportBox->m_pGrid;
            for (int row = pGrid->GetRowCount()-1; row >= pGrid->GetRowCount()-3; row--)
            {
            for (int col = 1; col <= pGrid->GetColumnCount(); col++)
            {
            GV_ITEM Item;
            Item.mask = GVIF_TEXT|GVIF_FORMAT;
            Item.row = row;
            Item.col = col;
            if(row==pGrid->GetRowCount()-3&&col>0) //平均值
            {
            if(col==10){
            Item.nFormat = DT_CENTER|DT_WORDBREAK;
            Item.szText.Format(_T(" %6.2f "),avjch);
            }
            else{
            Item.nFormat = DT_CENTER|DT_WORDBREAK;
            Item.szText.Format(_T(" %6.2f "),av[col-1]);
            }
            }
            pGrid->SetItem(&Item); //提交數(shù)據(jù)
            if(row==0||col==0)
            {
            COLORREF clr = RGB(0, 0, 0);
            pGrid->SetItemBkColour(row, col, clr);
            pGrid->SetItemFgColour(row, col, RGB(255,0,0));
            }
            }//循環(huán)結(jié)束
            pGrid->Invalidate();
            }
            好累啊,忙了一天時(shí)間終于寫(xiě)完了!


            posted on 2006-06-23 23:16 讓心飛翔 閱讀(10137) 評(píng)論(12)  編輯 收藏 引用 所屬分類(lèi): 編程經(jīng)驗(yàn)

            評(píng)論

            # re: GridCtrl使用詳解 2006-10-20 18:50
            你好,我想通過(guò)GridCtrl控件做個(gè)表格,表頭是2行,第1行是2列,第2行是4列,
            另在表格中,有一列不需要輸入數(shù)據(jù),只是讓他能顯示,選擇顏色.這個(gè)需要怎么設(shè)置?雙擊這列的表格中的某一行能夠調(diào)出顏色選擇對(duì)話框.  回復(fù)  更多評(píng)論
              

            # re: GridCtrl使用詳解 2006-11-21 12:51 xbgs
            @趁
            有這個(gè)類(lèi)的擴(kuò)展類(lèi),可以支持單元格合并,而且支持單元格擴(kuò)展。
            是兩個(gè)不同的擴(kuò)展類(lèi),需要的話留下email.  回復(fù)  更多評(píng)論
              

            # re:我需要能合并單元格的類(lèi),謝謝 2006-12-21 10:19 高工
            我的郵箱是:
            lingfeng12@163.com  回復(fù)  更多評(píng)論
              

            # re: GridCtrl使用詳解[未登錄](méi) 2007-04-24 17:39 Michael
            請(qǐng)問(wèn):現(xiàn)在有支持Debug的CGridCtrl版本嗎?  回復(fù)  更多評(píng)論
              

            # re: GridCtrl使用詳解 2007-12-21 11:51 秦歌
            頂一下  回復(fù)  更多評(píng)論
              

            # re: GridCtrl使用詳解 2008-01-03 09:46 scate
            如何實(shí)現(xiàn)單元格可以出現(xiàn)combbox那樣的下拉列表,然后選一個(gè)填入單元格中?我試著做了一下,但不成功,下拉選定之后,那個(gè)箭頭還在,沒(méi)有變回單元格  回復(fù)  更多評(píng)論
              

            # re: GridCtrl使用詳解[未登錄](méi) 2008-03-04 10:24 yang
            你好,可以把例子程序給我一份嗎?我做個(gè)動(dòng)態(tài)鏈接庫(kù),對(duì)話框里放GridCtrl顯示不出來(lái),謝謝!我郵箱yang97718@yahoo.com.cn  回復(fù)  更多評(píng)論
              

            # re: GridCtrl使用詳解 2009-02-17 21:24 sanfeng
            我都email
            sanfeng-114@163.com 給我也發(fā)一個(gè) 謝謝了e
              回復(fù)  更多評(píng)論
              

            # re: GridCtrl使用詳解[未登錄](méi) 2010-01-31 14:44 fox
            我照抄了,編譯通不過(guò)啊  回復(fù)  更多評(píng)論
              

            # re: GridCtrl使用詳解 2010-02-27 23:30 anturbo
            WIN7下連release都調(diào)試出錯(cuò),XP反而可以過(guò)一些  回復(fù)  更多評(píng)論
              

            # re: GridCtrl使用詳解 2011-08-12 09:55 wwb
            你好,能把這個(gè)GRID例子程序給我一份嗎?謝謝!wwbwwb2121@163.com  回復(fù)  更多評(píng)論
              

            # re: GridCtrl使用詳解 2011-08-24 20:18 光輝
            你好,不知道現(xiàn)在還用這個(gè)博客嗎?我需要 支持單元格合并 的GridCtrl類(lèi),我的郵箱是 ai_rengh@yahoo.com.cn,真希望您還有,上天保佑我啊,網(wǎng)絡(luò)上下載的都有很多很多bug  回復(fù)  更多評(píng)論
              

            日日躁夜夜躁狠狠久久AV| 亚洲精品无码久久久久久| 久久被窝电影亚洲爽爽爽| 亚洲国产成人久久精品动漫| 99久久精品国产一区二区三区| 久久精品?ⅴ无码中文字幕| 一本色道久久88综合日韩精品 | 欧美亚洲国产精品久久| 亚洲日韩中文无码久久| 久久久精品午夜免费不卡| 久久综合狠狠综合久久97色| 久久亚洲国产精品成人AV秋霞| 狠狠色婷婷综合天天久久丁香| 亚洲欧洲精品成人久久曰影片 | 狠狠色综合网站久久久久久久高清| 精品一二三区久久aaa片| 久久久中文字幕| 久久精品国产日本波多野结衣| 999久久久国产精品| 性高湖久久久久久久久| 欧美日韩中文字幕久久久不卡| 97久久精品人妻人人搡人人玩| 一本色道久久88综合日韩精品| 国产AⅤ精品一区二区三区久久| 色欲综合久久中文字幕网| 最新久久免费视频| 国内精品久久久久久久影视麻豆| 精品久久久久香蕉网| 亚洲精品白浆高清久久久久久| 久久99精品免费一区二区| 久久伊人精品青青草原高清| 久久久噜噜噜久久中文福利| 囯产精品久久久久久久久蜜桃| 狠狠色丁香久久婷婷综合图片| 久久九九久精品国产| 国产精品va久久久久久久| 女人香蕉久久**毛片精品| 国产V综合V亚洲欧美久久| 久久A级毛片免费观看| 久久久亚洲欧洲日产国码二区 | 国产亚州精品女人久久久久久 |