头文件
#pragma once
#include "D:Work山东项目StandardizedDrawingsdUtilsCSGrid.h"
#include "ZwLResources.h"
class CPaneGrid :
public CSGrid
{
public:
CPaneGrid(void);
~CPaneGrid(void);
protected:
DECLARE_MESSAGE_MAP()
protected:
virtual VOID OnCellComboString(CSGridCell&cell, CComboBox&combo);
// virtual VOID OnRClickRow(CSGridRow&row, CPoint point);
// virtual VOID OnRClickCol(CSGridCol&col, CPoint pt);
// virtual BOOL OnRowSelectChange(int nOldRow, int &nNewRow);
};
cpp文件
#include "StdAfx.h"
#include "PaneGrid.h"
#include "OdbcDatabase.h"
#include "GlobalArxUtils.h"
#include "GlobalUtils.h"
#include "CSGrid.h"
CPaneGrid::CPaneGrid() :CSGrid(FALSE)
{
AppendColumn(_T("属性名称"), 70);
AppendColumn(_T("值"), 120);
GetCol(GetColumnCount() - 1).SetComboEdit(TRUE);
}
BEGIN_MESSAGE_MAP(CPaneGrid, CSGrid)
END_MESSAGE_MAP()
CPaneGrid::~CPaneGrid(void)
{
}
VOID CPaneGrid::OnCellComboString(CSGridCell&cell, CComboBox&combo)
{
long lIndexRow = cell.GetRowIndex();
long lIndexCol = cell.GetColIndex();
CSGridCell cellNmae=CSGrid::GetCell(lIndexRow, lIndexCol-1);
CString ProName=cellNmae.GetText();
CString sDatabase;
sDatabase.Format(_T("%sData\%s"), GetAppRoot(), SDDATABASE);
COdbcDatabase db;
CString sQuery;
CStringList slResults;
CString sValue;
if (db.InitializeWithPath(sDatabase))
{
sQuery.Format(
_T("SELECT AlternativeValue FROM ")
_T("%s ") _T("WHERE [PropertyName] = '%s'"),
TABLE_CUSTOMPROPERTY, ProName);
slResults.RemoveAll();
db.GetQuery(sQuery, slResults);
}
POSITION rPos;
rPos = slResults.GetHeadPosition();
while (rPos != NULL)
{
sValue = slResults.GetNext(rPos);
//拆分字符串
CStringArray saCf;
int iPos = -1;
while ((iPos = sValue.Find(',')) != -1)
{
saCf.Add(sValue.Left(iPos));
sValue.Delete(0, iPos + 1);
}
saCf.Add(sValue);
int iNum=saCf.GetCount();
for (int i = 0; i < iNum;i++)
{
combo.AddString(saCf.GetAt(i));
}
}
return CSGrid::OnCellComboString(cell, combo);
}
重定义csgrid 然后用新定义的类去创建函数