Пример #1
0
int CIBAGrid::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CBCGPGridCtrl::OnCreate(lpCreateStruct) == -1)
		return -1;

	SetReadOnly();//只读
	SetWholeRowSel();//整行选中
	SetSingleSel(FALSE);//单选
	EnableHeader(TRUE, 0);//列表头使能

	// Set grid colors
	CBCGPGridColors colors;
	colors.m_LeftOffsetColors.m_clrBackground = globalData.clrWindow;
	colors.m_OddColors.m_clrBackground = RGB(238, 246, 255);// 设置奇数行的背景色
	//colors.m_SelColors.m_clrBackground = RGB(50, 50, 180);

	SetColorTheme(colors);//颜色调配器
	
	SetScrollBarsStyle(CBCGPScrollBar::BCGP_SBSTYLE_VISUAL_MANAGER);//滚动栏样式

	return 0;
}
/**
 * @brief 创建列表网格
 * @note  
 * @param  
 * @return 
 */
void	CGridCtrlList::CreateGrid(CRect& rc,CWnd* pParent)
{
	Create (WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER , rc, pParent, (UINT)-1);
	// 禁止列排序
	EnableHeader (FALSE, BCGP_GRID_HEADER_HIDE_ITEMS);		
	EnableColumnAutoSize(FALSE);
	EnableDragHeaderItems(FALSE);
	SetReadOnly ();
	SetSingleSel(TRUE);
	SetWholeRowSel(TRUE);
	EnableDragSelection(FALSE);
	SetScrollBarsStyle(CBCGPScrollBar::BCGP_SBSTYLE_DEFAULT);
	ShowVertScrollBar();

	BCGP_GRID_COLOR_DATA clrData;
	clrData = GetColorTheme();
	//clrData.m_clrBackground = globalData.clrWindow; //::GetSysColor(COLOR_3DFACE);
	clrData.m_EvenColors.m_clrBackground = RGB(255,255,255);
	clrData.m_OddColors.m_clrBackground = RGB(250,253,253);

	SetColorTheme(clrData);
	AdjustLayout();
}
//*********************************************************************
BOOL CCxNDArrayDimGrid::Init( CRect& rc, CWnd * pParent )
{
	if ( IsWindow(m_hWnd) ) return FALSE;

	Create (WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER, rc, pParent, ID_NAE_ARRAY_DIM);

	EnableColumnAutoSize (FALSE);
	SetSingleSel (TRUE);
	EnableGroupByBox (FALSE);
	SetReadOnly (FALSE);
	SetWholeRowSel (FALSE);
	EnableHeader (TRUE, 0);
	m_nBaseHeight = 20;

	// Set grid tab order (first):
	SetWindowPos (&CWnd::wndTop, -1, -1, -1, -1, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
	//	SetSelectionBorder(FALSE);

	//m_bGridItemBorders = TRUE;
	//m_bHighlightActiveItem = FALSE;
	//m_bDrawFocusRect = FALSE;
	//m_bSelectionBorder = FALSE;

	CBCGPGridColors colors;

	colors.m_clrBackground = g_crStructTreeClientBg;	// Grid background color
	//colors.m_clrText;			// Grid foreground color
	//colors.m_clrHeader;		// H foreground color

	//colors.m_EvenColors;		// Even rows color
	//colors.m_OddColors;		// Odd rows color

	//colors.m_GroupColors;		// Group colors
	colors.m_GroupSelColors.m_clrBackground = g_crStructTreeSelItemBg;	// Selected group colors

	colors.m_SelColors.m_clrBackground = g_crStructTreeSelItemBg;		// Selected rows color

	colors.m_HeaderColors.m_clrBackground = g_crStructTreeHeaderBg;		// Header item color
	//colors.m_HeaderSelColors;	// Selected header item color

	colors.m_LeftOffsetColors.m_clrBackground = g_crStructTreeClientBg;	// Left offset colors

	//colors.m_clrHorzLine = g_crStructTreeClientBg;		// Grid horizontal line text
	//colors.m_clrVertLine = g_crStructTreeClientBg;		// Grid vertical line text

	//colors.m_clrPreviewText;	// Description text color

	SetColorTheme (colors);

	//SetSelectionBorderForActiveItem(FALSE);
	//SetSelectionBorder(FALSE);


	//////////////////////////////////////////////////////////////////////////

	CString str;
	int nColCnt = 0;
	int nRowCnt = 0;
	CCxNDArrayDimItem* pItem = NULL;
	CCxNDArrayDimRow * pRow = NULL;

	nColCnt = sizeof( arrDimColCaption ) / sizeof( LPCTSTR );
	for (int i=0; i<nColCnt; i++)
	{
		InsertColumn (i, arrDimColCaption[i], arrDimColWidth[i]);
	}
	if ( m_pArrayData != NULL )
	{
		nRowCnt = m_pArrayData->GetDimCount();
		for ( int i=0; i<nRowCnt; i++ )
		{
			//if ( nRowCnt <= 2 )
			//{
			//	break;
			//}

			pRow = CreateNewRow ();
			pRow->AllowSubItems (FALSE);
			for (int col = 0; col < nColCnt; col++)
			{
				switch (col)
				{
				case COL_DIM_INDEX:
				case COL_DIM_TYPE:
				case COL_DIM_VALUE:
					pRow->GetItem(col)->AllowEdit(FALSE);
					break;
				default:
					break;
				}
			}

			str.Format("%d", i);
			pRow->GetItem (COL_DIM_INDEX)->SetValue( (LPCTSTR)str );

			CString strSel;
			switch (i)
			{
			case 0:
				strSel = "Row"; break;
			case 1:
				strSel = "Column"; break;
			//case 2:
			//	strSel = "Column"; break;
			default:
				strSel = "Index"; break;
			}

			pItem = new CCxNDArrayDimItem ( (LPCTSTR)strSel );
			if ( nRowCnt > 0 ) 
				pItem->AddOption ( "Row", 1 );
			if ( nRowCnt > 1 )
				pItem->AddOption ( "Column", 1 );
			if ( nRowCnt > 2 )
				pItem->AddOption ( "Index", 1 );
			pRow->ReplaceItem (COL_DIM_TYPE, pItem);

			if ( nRowCnt <= 2 ) 
			{
				pRow->GetItem( COL_DIM_TYPE )->Enable(FALSE);
				pRow->GetItem( COL_DIM_TYPE )->AllowEdit(FALSE);
			}

			pItem = new CCxNDArrayDimItem ( 0 ); 
			pItem->EnableSpinControl(TRUE, 0, m_pArrayData->GetDataCount( nRowCnt-i-1 ) - 1 );
			pRow->ReplaceItem (COL_DIM_VALUE, pItem);

			switch (i)
			{
			case 2: //row col
			case 1:
				pRow->GetItem( COL_DIM_VALUE )->Enable( FALSE ); break;
			default:
				break;
			}

			AddRow (pRow, FALSE);
		}

		//if ( nRowCnt == 2 )
		//{
		//	GetRow(0)->GetItem(COL_DIM_TYPE)->Enable(FALSE);
		//	GetRow(0)->GetItem(COL_DIM_VALUE)->Enable(FALSE);
		//}

		//if ( nRowCnt == 1 )
		//{
		//	GetRow(0)->GetItem(COL_DIM_TYPE)->Enable(FALSE);
		//	GetRow(0)->GetItem(COL_DIM_VALUE)->Enable(FALSE);
		//	GetRow(1)->GetItem(COL_DIM_TYPE)->Enable(FALSE);
		//	GetRow(1)->GetItem(COL_DIM_VALUE)->Enable(FALSE);
		//	GetRow(2)->GetItem(COL_DIM_TYPE)->Enable(FALSE);
		//	GetRow(2)->GetItem(COL_DIM_VALUE)->Enable(FALSE);
		//}
	}
	m_nButtonWidth = 20;
	AdjustLayout();
	return TRUE;
}