List - 多选,插入,删除示例.

说明

List多选,插入,删除示例.

List_Item.xml

<?xml version="1.0" ?>
<xc_template_list>
<listHeader_item>
<layoutEleUI type="item" layout.horizon="true" layout.alignH="left" layout.alignV="center" layout.width="fill" layout.height="fill" layout.space="6" layout.padding="5,2,2,2" >
<shapeText itemID="1" layout.width="auto" layout.height="fill" content="{binding field=name1 source=data bSync=false}" />
</layoutEleUI>
<layoutEleUI type="item" layout.horizon="true" layout.alignH="left" layout.alignV="center" layout.width="fill" layout.height="fill" layout.space="6" layout.padding="5,2,2,2" >
<shapeText itemID="2" layout.width="auto" layout.height="fill" content="{binding field=name2 source=data bSync=false}" />
</layoutEleUI>
<layoutEleUI type="item" layout.horizon="true" layout.alignH="left" layout.alignV="center" layout.width="fill" layout.height="fill" layout.space="6" layout.padding="5,2,2,2" >
<shapeText itemID="3" layout.width="auto" layout.height="fill" content="{binding field=name3 source=data bSync=false}" />
</layoutEleUI>
</listHeader_item>
<list_Item>
<layoutEleUI type="item" layout.horizon="true" layout.alignH="left" layout.alignV="center" layout.width="fill" layout.height="fill" layout.space="6" layout.padding="2,2,2,2" >
<shapeText itemID="1" layout.width="auto" layout.height="fill" content="{binding field=name1 source=data bSync=false}" />
<buttonUI itemID="11" width="60" height="18" content="{binding field=name1 source=data bSync=false}" />
</layoutEleUI>
<layoutEleUI type="item" layout.horizon="true" layout.alignH="left" layout.alignV="center" layout.width="fill" layout.height="fill" layout.space="2" layout.padding="2,2,2,2" >
<shapeText itemID="2" layout.width="auto" layout.height="fill" content="{binding field=name2 source=data bSync=false}" />
<buttonUI itemID="22" width="70" height="18" content="{binding field=name2 source=data bSync=false}" />
</layoutEleUI>
<layoutEleUI type="item" layout.horizon="true" layout.alignH="left" layout.alignV="center" layout.width="fill" layout.height="fill" layout.space="2" layout.padding="2,2,2,2" >
<shapeText itemID="3" layout.width="auto" layout.height="fill" content="{binding field=name3 source=data bSync=false}" />
<buttonUI itemID="33" width="70" height="18" content="{binding field=name3 source=data bSync=false}" />
</layoutEleUI>
</list_Item>
</xc_template_list>

示例代码

class CMyWindowList
{
public:
HWINDOW m_hWindow;
HELE m_hList;
HELE m_hEidt;
CMyWindowList()
{
Init();
}
void Init()
{
m_hWindow = XWnd_Create(0, 0, 700, 400, L"炫彩界面库窗口", NULL, window_style_default);
m_hList = XList_Create(20, 40, 500, 300, m_hWindow);
XList_SetItemTemplateXML(m_hList, L"XML-template-test\\List_Item.xml");
XSView_SetLineSize(m_hList, 20, 20);
XList_AddColumn(m_hList, 100);
XList_AddColumn(m_hList, 100);
XList_AddColumn(m_hList, 100);
HXCGUI hAdapterHeader = XAdMap_Create();
XList_BindAdapterHeader(m_hList, hAdapterHeader);
XAdMap_AddItemText(hAdapterHeader, XC_NAME1, L"aaa");
XAdMap_AddItemText(hAdapterHeader, XC_NAME2, L"bbb");
XAdMap_AddItemText(hAdapterHeader, XC_NAME3, L"ccc");
XAdMap_AddItemText(hAdapterHeader, XC_NAME4, L"test");
HXCGUI hAdapter = XAdTable_Create();
XList_BindAdapter(m_hList, hAdapter);
XAdTable_AddColumn(hAdapter, XC_NAME1);
XAdTable_AddColumn(hAdapter, XC_NAME2);
XAdTable_AddColumn(hAdapter, XC_NAME3);
XList_SetColumnWidth(m_hList, 0, 150);
XList_SetColumnWidth(m_hList, 1, 150);
XList_SetColumnWidth(m_hList, 2, 150);
wchar_t tmp[MAX_PATH] = { 0 };
for (int i = 0; i < 20; i++)
{
wsprintf(tmp, L"item-%d", i);
XAdTable_AddItemText(hAdapter, tmp);
wsprintf(tmp, L"child-%d-1", i); XAdTable_SetItemText(hAdapter, i, 1, tmp);
wsprintf(tmp, L"child-%d-2", i); XAdTable_SetItemText(hAdapter, i, 2, tmp);
}
m_hEidt = XEdit_Create(525, 106, 120, 200, m_hWindow);
XSView_ShowSBarV(m_hEidt, TRUE);
XEdit_EnableMultiLine(m_hEidt, TRUE);
HELE hButton1 = XBtn_Create(525, 40, 100, 18, L"插入index=1", m_hWindow);
XEle_RegEventCPP(hButton1, XE_BNCLICK, &CMyWindowList::OnBtnClickInsert);
HELE hButton2 = XBtn_Create(525, 62, 100, 18, L"删除index=1", m_hWindow);
XEle_RegEventCPP(hButton2, XE_BNCLICK, &CMyWindowList::OnBtnClickDel);
HELE hButton3 = XBtn_Create(525, 84, 100, 18, L"删除index=(2-3)", m_hWindow);
XEle_RegEventCPP(hButton3, XE_BNCLICK, &CMyWindowList::OnBtnClickDelEx);
XEle_RegEventCPP(m_hList, XE_LIST_SELECT, &CMyWindowList::OnListSelect);
XEle_RegEventCPP(m_hList, XE_LIST_TEMP_CREATE, &CMyWindowList::OnTemplateCreate);
XEle_RegEventCPP(m_hList, XE_LIST_TEMP_DESTROY, &CMyWindowList::OnTemplateDestroy);
XWnd_ShowWindow(m_hWindow, SW_SHOW);
}
int OnBtnClickInsert(BOOL* pbHandled)
{
HXCGUI hAdapter = XList_GetAdapter(m_hList);
int index = XAdTable_InsertItemText(hAdapter, 1, L"test-insert");
XAdTable_SetItemText(hAdapter, index, 1, L"insert");
XAdTable_SetItemText(hAdapter, index, 2, L"insert");
XEle_Redraw(m_hList);
return 0;
}
int OnBtnClickDel(BOOL* pbHandled)
{
HXCGUI hAdapter = XList_GetAdapter(m_hList);
if (XAdTable_DeleteItem(hAdapter, 1))
XEle_Redraw(m_hList);
return 0;
}
int OnBtnClickDelEx(BOOL* pbHandled)
{
HXCGUI hAdapter = XList_GetAdapter(m_hList);
if (XAdTable_DeleteItemEx(hAdapter, 2, 2))
XEle_Redraw(m_hList);
return 0;
}
int OnListSelect(int iItem, BOOL* pbHandled)
{
XTRACEA("select item %d \n", iItem);
int array_[100] = { 0 };
int count = XList_GetSelectAll(m_hList, array_, 100);
wstring szItemList;
HXCGUI hAdapter = XList_GetAdapter(m_hList);
for (int i = 0; i < count; i++)
{
szItemList += XAdTable_GetItemTextEx(hAdapter, array_[i], XC_NAME1);
szItemList += L"\n";
}
XEdit_SetText(m_hEidt, szItemList.c_str());
XEle_Redraw(m_hEidt);
return 0;
}
int OnTemplateCreate(list_item_i* pItem, int nFlag, BOOL* pbHandled)
{
return 0;
}
int OnTemplateDestroy(list_item_i* pItem, int nFlag, BOOL* pbHandled)
{
return 0;
}
};
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
XInitXCGUI(TRUE);
CMyWindowList MyWindowt;
return 0;
}
#define XE_BNCLICK
按钮点击事件.
Definition: XCGUI.h:939
#define XE_LIST_SELECT
列表元素,项选择事件.
Definition: XCGUI.h:1038
#define XE_LIST_TEMP_DESTROY
列表元素,项模板销毁.
Definition: XCGUI.h:1026
#define XE_LIST_TEMP_CREATE
列表元素-项模板创建事件,模板复用机制需先启用;替换模板无效判断nFlag,因为内部会检查模板是否改变,不用担心重复
Definition: XCGUI.h:1015
@ window_style_default
窗口样式-控制按钮: 居中 图标, 标题, 关闭按钮, 最大化按钮, 最小化按钮
Definition: XCGUI.h:398
HELE WINAPI XBtn_Create(int x, int y, int cx, int cy, const wchar_t *pName, HXCGUI hParent)
按钮_创建 创建按钮元素
Definition: ButtonUI.cpp:1765
void WINAPI XEdit_SetText(HELE hEle, const wchar_t *pString)
@编辑框_置文本
Definition: EditUI.cpp:6856
HELE WINAPI XEdit_Create(int x, int y, int cx, int cy, HXCGUI hParent)
@编辑框_创建 创建
Definition: EditUI.cpp:6572
void WINAPI XEdit_EnableMultiLine(HELE hEle, BOOL bEnable)
@编辑框_启用多行
Definition: EditUI.cpp:6620
void WINAPI XEle_Redraw(HELE hEle, BOOL bImmediate)
元素_重绘 重绘元素.
Definition: EleUI.cpp:4179
void WINAPI XSView_ShowSBarV(HELE hEle, BOOL bShow)
滚动视_显示垂直滚动条 显示垂直滚动条.
Definition: ScrollViewUI.cpp:836
BOOL WINAPI XSView_SetLineSize(HELE hEle, int nWidth, int nHeight)
滚动视_置滚动单位大小 设置滚动单位大小.
Definition: ScrollViewUI.cpp:694
void WINAPI XExitXCGUI()
炫彩_退出 退出界面库释放资源. 不可在dllmain()中卸载, 否则会死锁
Definition: App.cpp:572
void WINAPI XRunXCGUI()
炫彩_运行 运行消息循环,当炫彩窗口数量为0时退出.
Definition: App.cpp:564
BOOL WINAPI XInitXCGUI(BOOL bD2D)
炫彩_初始化 初始化界面库.
Definition: App.cpp:557
void * HXCGUI
资源句柄
Definition: XCGUI.h:92
XEle_RegEventCPP(hEle, nEvent, memberFunction)
元素_注册事件CPP 注册元素事件,将类成员函数作为事件响应函数.函数省略元素自身句柄hEle.
HXCGUI WINAPI XAdMap_Create()
数据适配器MAP_创建 创建数据适配器,单列数据.数据适配器存储数据, UI对象根据绑定的字段名显示数据适配器中对应的数据;
Definition: DataAdapter.cpp:2441
BOOL WINAPI XAdMap_AddItemText(HXCGUI hAdapter, const wchar_t *pName, const wchar_t *pValue)
数据适配器MAP_添加项文本 增加数据项.
Definition: DataAdapter.cpp:2452
int WINAPI XAdTable_AddColumn(HXCGUI hAdapter, const wchar_t *pName)
数据适配器表_添加列 添加数据列.
Definition: DataAdapter.cpp:1908
HXCGUI WINAPI XAdTable_Create()
数据适配器表_创建 创建列表框元素数据适配器.数据适配器存储数据, UI对象根据绑定的字段名显示数据适配器中对应的数据;
Definition: DataAdapter.cpp:1863
const wchar_t *WINAPI XAdTable_GetItemTextEx(HXCGUI hAdapter, int iRow, const wchar_t *pName)
数据适配器表_取项文本扩展 获取项文本内容.
Definition: DataAdapter.cpp:2201
BOOL WINAPI XAdTable_SetItemText(HXCGUI hAdapter, int iRow, int iColumn, const wchar_t *pValue)
数据适配器表_置项文本 设置项数据.
Definition: DataAdapter.cpp:2031
BOOL WINAPI XList_SetItemTemplateXML(HELE hEle, const wchar_t *pXmlFile)
列表_置项模板文件 设置项布局模板文件.
Definition: ListUI.cpp:4565
void WINAPI XList_BindAdapter(HELE hEle, HXCGUI hAdapter)
列表_绑定数据适配器 绑定数据适配器.
Definition: ListUI.cpp:4479
HXCGUI WINAPI XList_GetAdapter(HELE hEle)
列表_取数据适配器 获取数据适配器.
Definition: ListUI.cpp:4545
HELE WINAPI XList_Create(int x, int y, int cx, int cy, HXCGUI hParent)
列表_创建 创建列表元素.
Definition: ListUI.cpp:4112
void WINAPI XList_SetColumnWidth(HELE hEle, int iRow, int width)
列表_置列宽 设置列宽度.
Definition: ListUI.cpp:4309
int WINAPI XList_AddColumn(HELE hEle, int width)
列表_增加列 增加列.
Definition: ListUI.cpp:4175
int WINAPI XList_GetSelectAll(HELE hEle, out_buffer_ int *pArray, int nArraySize)
列表_取全部选择 获取全部选择的行.
Definition: ListUI.cpp:4431
void WINAPI XList_BindAdapterHeader(HELE hEle, HXCGUI hAdapter)
列表_列表头绑定数据适配器 列表头绑定数据适配器.
Definition: ListUI.cpp:4489
HWINDOW WINAPI XWnd_Create(int x, int y, int cx, int cy, const wchar_t *pTitle, HWND hWndParent, int XCStyle)
窗口_创建 创建窗口
Definition: WindowUI.cpp:5964
BOOL WINAPI XWnd_ShowWindow(HWINDOW hWindow, int nCmdShow)
@窗口_显示扩展 显示隐藏及控制窗口最大化还原等
Definition: WindowUI.cpp:6387

程序截图