2.2.6.18.1 GridListControl::CancelSelRows


Description

Unselect rows.

Syntax

void CancelSelRows( const vector<int> vnRows )

Parameters

vnRows
[input] indexes of unselected rows

Return

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, 0, 5, 1 );
		
		//move grid control to top left
		RECT rrList;	
		rrList.top = rrList.left = GetControlGap();
		m_GridCtrl.MoveWindow(rrList);
		
		GetItem(IDOK).Text = "Test";//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()
	{
		vector<string> vval={"a","b","c","d","e"};
		for(int kk=0;kk<m_GridCtrl.GetRows();kk++)
			m_GridCtrl.SetCell(kk,0,vval[kk]);
		vector<int> vcc={2};
		vector<int> vsr={1,2,3};
		vector<uint> vsel;
		vector<string> vstr;
		printf("%s",m_GridCtrl.CheckSelRow(3,true)?"Success to select\n":"Select Already\n");//0-offset
		printf("%s",m_GridCtrl.CheckSelRow(3,true)?"Success to select\n":"Select Already\n");
		m_GridCtrl.SetSelection(flexSelectionListBox);
		m_GridCtrl.SetRowsIsSelected(2,4,true);
		out_int("number of selected rows now:",m_GridCtrl.SelectedRows());
		m_GridCtrl.GetSelItems(0,vstr);
		for(int jj=0;jj<vstr.GetSize();jj++)
			printf("%s",vstr[jj]);
		printf("\n");
		out_int("selected row: ",m_GridCtrl.GetSelectedRow());
		m_GridCtrl.CancelSelRows(vcc);//rowoffset-offset
		m_GridCtrl.SelRows(vsr);
		m_GridCtrl.GetSelRows(vsel);//if selection mode!=flexSelectionListBox,only row 2 will be selected
		for(int ii=0;ii<vsel.GetSize();ii++)
			printf("%d",vsel[ii]);
		printf("\n");
		m_GridCtrl.GetSelItems(0,vstr);
		for(int ij=0;ij<vstr.GetSize();ij++)
			printf("%s",vstr[ij]);
		m_GridCtrl.RemoveSelection();
		out_int("\nnumber of selected rows now:",m_GridCtrl.SelectedRows());
		m_GridCtrl.SelRow(3,false);	
		printf("%s",m_GridCtrl.GetIsSelected(3)?"Row 3 is selected\n":"wrong\n");	
	}
	
private:
	GridListControl         m_GridCtrl;
};
bool OpenGridDLG()    
{
	GridCtrlDLG myDlg;
	myDlg.DoModal( GetWindow() );
	return true;
}

Remark

See Also

Header to Included

GridControl.h