码迷,mamicode.com
首页 > 其他好文 > 详细

listcontrol 加combobox实现

时间:2015-09-10 15:45:33      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

头文件

#pragma once
#include "D:\Work\山东项目\StandardizedDrawing\sdUtils\CSGrid.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 然后用新定义的类去创建函数

listcontrol 加combobox实现

标签:

原文地址:http://www.cnblogs.com/xzh1993/p/4797735.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!