GridControl::FindRow

 

Contents

Description

Returns the index of a row that contains a specified string.


Returns the index of a row that contains a specified RowData value.

Syntax

int FindRow( LPCSTR lpcszRowText, int nCol = 0, bool bCaseSensitive = false, bool bFullmatch = true, int nStartRow = -1 )

int FindRow( DWORD dwData )

Parameters

lpcszRowText
[input] the string being searched
nCol
[input] specify which column should be searched
bCaseSensitive
[input] true means the search is case-sensitive
bFullmatch
[input] true means the search is for a full match
nStartRow
[input] specify the row where the search should start. the search starts from non-fixed row if nStartRow = -1.

dwData
[input] the data being searched.

Return

row number if found otherwise return -1


row number if found otherwise return -1

Examples

The examples in this section will use an existing grid dialog resource DLL that gets installed with Origin C's Developer Kit. The DLL can be found in this zip file, under \Dialog Builder\GridDLG sub-folder.

#include <..\Originlab\DialogEx.h>
#include "GridDLGRes.h"// resource DLL header

class GridCtrlDLG : public ResizeDialog
{
public:
        GridCtrlDLG() : ResizeDialog(IDD_GRID_DLG, "GridDLG")
        {
        }

        int DoModal(HWND hParent = NULL)
        {
                InitMsgMap();
                int nRet = ResizeDialog::DoModal(hParent);
                return nRet;
        }

protected:
///----------------- Message Map ----------------
        EVENTS_BEGIN
                ON_INIT(OnInitDialog)
                ON_SIZE(OnDlgResize)
                ON_GETMINMAXINFO(OnMinMaxInfo)
                ON_OK(OnOK)
        EVENTS_END
///----------------------------------------------
        
        BOOL OnInitDialog()
        {
                ResizeDialog::OnInitDialog(0, "Grid Dialog");
                
                //initialize grid control
                m_GridCtrl.Init(IDC_GRID, *this);
                m_GridCtrl.SetupRowsCols( 1, 1, 5, 2 );
                
                vector<string> vsItems = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
                vector<string> vsItems2 = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul"};
                m_GridCtrl.CheckExpandRows( vsItems.GetSize()- m_GridCtrl.GetRowOffset() );
                m_GridCtrl.SetCells(vsItems, 0);
                m_GridCtrl.SetCells(vsItems2, 1);
                
                //move grid control to top left
                RECT rrList;    
                rrList.top = rrList.left = GetControlGap();
                m_GridCtrl.MoveWindow(rrList);
                
                GetItem(IDOK).Text = "Search";//for example codes
                
                SetInitReady();
                return TRUE;
        }     

        BOOL OnDlgResize(int nType, int cx, int cy)
        {
                if(!IsInitReady())
                        return TRUE;          
                
                uint nButtonIDs[] = {IDOK, 0};
                
                ArrangeMainItemAndControls(nButtonIDs, IDC_GRID, NULL, false);
                return TRUE;
                
        }
        
        BOOL OnOK()
        {
                doExample();
                
                return FALSE;
        }
        
private:
        void doExample()
        {
                string strName = InputBox("Please enter keyword to search", "");
                for(int ii=m_GridCtrl.GetColOffset();ii<m_GridCtrl.GetCols();ii++)
                {
                        int result=m_GridCtrl.FindRow(strName,ii);
                        if(result!=-1)
                {
                        out_int("col=",ii+1-m_GridCtrl.GetColOffset());
                        out_int("row=",result+1-m_GridCtrl.GetRowOffset());
                        return;
                }
                }
        }
        
private:
        GridControl         m_GridCtrl;
};

bool OpenGridDLG()    
{
        GridCtrlDLG myDlg;
        myDlg.DoModal( GetWindow() );
        return true;
}

Remark

See Also

header to Included

GridControl.h