新增:单元格编辑完成回调;单击第一列选中整行
This commit is contained in:
@@ -7,6 +7,28 @@ void mainForm::OnNotify(Control* sender, EventArgs& args)
|
||||
UIString btnName = sender->Name; // 控件id
|
||||
Event eventType = args.EventType; // 事件类型
|
||||
|
||||
// 针对管理界面的表格控件
|
||||
if (btnName == "tableViewAdmin") {
|
||||
switch (eventType)
|
||||
{
|
||||
case 8: break;
|
||||
case Event::OnMouseUp://鼠标抬起
|
||||
{
|
||||
TableView* tableView = (TableView*)FindControl("tableViewAdmin"); //获取表格控件
|
||||
int pRow = tableView->GetHoverRow(); //当前行号
|
||||
int pCol = tableView->GetHoverCol(); //当前列号
|
||||
std::cout << "当前行列号: (" << pRow << ", " << pCol << ")\n";
|
||||
UIString celContent = tableView->GetData(pRow, pCol);
|
||||
std::cout << "单元格内容: " << celContent.ansi() << std::endl;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
std::cout << "表格事件:" << (long long)eventType << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (eventType)
|
||||
{
|
||||
case ezui::OnMouseDown: //鼠标按下
|
||||
@@ -56,13 +78,15 @@ void mainForm::OnNotify(Control* sender, EventArgs& args)
|
||||
}
|
||||
|
||||
TableView* tableView = (TableView*)FindControl("tableViewAdmin"); //获取表格控件
|
||||
if (tableView) {
|
||||
tableView->SetColumnType(4, ezui::CellType::CheckBox);
|
||||
tableView->SetColumnType(5, ezui::CellType::ComboBox);
|
||||
tableView->SetColumnComboItems(5, {L"选择1", L"选择2" , L"选择3" });
|
||||
tableView->InsertRow(1);
|
||||
tableView->SetRowData(tableView->GetRowCount() - 1, {L"uid1", L"192.168.200.131"});
|
||||
if (tableView){
|
||||
int rowCount = tableView->GetRowCount(); //总行数
|
||||
// 表格增加一行数据
|
||||
tableView->InsertRow(rowCount);
|
||||
tableView->SetRowData(rowCount, { L"uid" + std::to_wstring(rowCount), L"192.168.200.131" , L"默认"});
|
||||
// 获取表格指定位置数据
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -99,6 +123,22 @@ mainForm::mainForm() :LayeredWindow(1000, 750)
|
||||
SetMiniSize(Size(600, 450)); // 设置最小尺寸
|
||||
umg.LoadXml("res/mainForm.htm");//加载xml里面的控件与样式
|
||||
umg.SetupUI(this);
|
||||
|
||||
AllocConsole();
|
||||
FILE* fp = nullptr;
|
||||
freopen_s(&fp, "CONOUT$", "w", stdout);
|
||||
freopen_s(&fp, "CONOUT$", "w", stderr);
|
||||
|
||||
// 初始化设置表格各项属性
|
||||
TableView* tableView = (TableView*)FindControl("tableViewAdmin"); //获取表格控件
|
||||
if (tableView) {
|
||||
tableView->SelectedRowBackColor = Color(200, 230, 255); // 设置选中行背景色
|
||||
tableView->SetColumnType(5, ezui::CellType::CheckBox);
|
||||
tableView->SetColumnType(2, ezui::CellType::ComboBox);
|
||||
tableView->SetColumnComboItems(2, { L"默认", L"禁止" , L"验机" });
|
||||
//设置列宽
|
||||
//std::vector<int> withs = {80, 100};
|
||||
}
|
||||
}
|
||||
|
||||
mainForm::~mainForm()
|
||||
|
||||
@@ -159,6 +159,12 @@ namespace ezui {
|
||||
int m_lastClickRow = -1;
|
||||
int m_lastClickCol = -1;
|
||||
|
||||
// 选中行(非CheckBox模式下,通过单击第一列选中的行)
|
||||
int m_selectedRow = -1;
|
||||
|
||||
// 编辑前的原始值(用于编辑完成回调)
|
||||
UIString m_editOriginalValue;
|
||||
|
||||
private:
|
||||
void Init();
|
||||
|
||||
@@ -236,13 +242,17 @@ namespace ezui {
|
||||
virtual const Size& GetContentSize() override;
|
||||
|
||||
public:
|
||||
// 选中行背景色(当第一列为CheckBox且被选中时使用)
|
||||
// 选中行背景色(当第一列为CheckBox且被选中时使用,或者单击选中行时使用)
|
||||
Color SelectedRowBackColor = Color(0xFFADD8E6); // 浅蓝色
|
||||
|
||||
// 单元格内容变化回调
|
||||
// 单元格内容变化回调(内容变化时立即触发)
|
||||
// 参数: row, col, newValue
|
||||
std::function<void(int, int, const UIString&)> CellValueChanged = nullptr;
|
||||
|
||||
// 单元格编辑完成回调(编辑结束时触发,比如TextBox失去焦点或按Enter时)
|
||||
// 参数: row, col, oldValue, newValue
|
||||
std::function<void(int, int, const UIString&, const UIString&)> CellEditFinished = nullptr;
|
||||
|
||||
public:
|
||||
TableView(Object* parentObject = nullptr);
|
||||
virtual ~TableView();
|
||||
@@ -376,6 +386,15 @@ namespace ezui {
|
||||
// 获取所有选中的行索引
|
||||
std::vector<int> GetCheckedRows() const;
|
||||
|
||||
// 获取当前选中的行(非CheckBox模式,通过单击第一列选中)
|
||||
int GetSelectedRow() const;
|
||||
|
||||
// 设置当前选中的行(非CheckBox模式)
|
||||
void SetSelectedRow(int row);
|
||||
|
||||
// 清除选中行(非CheckBox模式)
|
||||
void ClearSelection();
|
||||
|
||||
// 全选
|
||||
void SelectAll();
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,106 +0,0 @@
|
||||
#include "pch.h"
|
||||
#include "mainForm.h"
|
||||
|
||||
|
||||
void mainForm::OnNotify(Control* sender, EventArgs& args)
|
||||
{
|
||||
UIString btnName = sender->Name; // 控件id
|
||||
Event eventType = args.EventType; // 事件类型
|
||||
|
||||
switch (eventType)
|
||||
{
|
||||
case ezui::OnMouseDown: //鼠标按下
|
||||
{
|
||||
if (btnName == "btnExitMain") { //退出
|
||||
int result = ::MessageBoxW(Hwnd(), L"要退出程序吗?", L"提示", MB_YESNO | MB_ICONQUESTION);
|
||||
if (result == IDYES)
|
||||
exit(0);
|
||||
}
|
||||
else if (btnName == "btnMinMain") { //最小化
|
||||
this->ShowMinimized();
|
||||
}
|
||||
else if (btnName == "btnMaxMain") { //最大化|还原
|
||||
if (this->IsMaximized()) {
|
||||
this->ShowNormal();
|
||||
// 修改控件文字
|
||||
Button* btnMax = (Button*)FindControl("btnMaxMain");
|
||||
btnMax->SetText(L"🗖");
|
||||
}
|
||||
else {
|
||||
this->ShowMaximized();
|
||||
// 修改控件文字
|
||||
Button* btnMax = (Button*)FindControl("btnMaxMain");
|
||||
btnMax->SetText(L"🗗");
|
||||
}
|
||||
}
|
||||
else if (btnName == "btnAdmin") { //到管理页面 获取 mainTab ,设置页面为0
|
||||
TabLayout* mainTab = (TabLayout*)FindControl("mainTab");
|
||||
mainTab->SetPageIndex(0);
|
||||
mainTab->Invalidate();
|
||||
}
|
||||
else if (btnName == "btnTools") { //到工具页面 获取 mainTab ,设置页面为1
|
||||
TabLayout* mainTab = (TabLayout*)FindControl("mainTab");
|
||||
mainTab->SetPageIndex(1);
|
||||
mainTab->Invalidate();
|
||||
}
|
||||
else if (btnName == "btnAdminConnect") { //管理页面的连接按钮按下,先获取 btnAdminConnect 按钮,设置为不可用,修改文字为“连接中...”
|
||||
Button* btnAdminConnect = (Button*)FindControl("btnAdminConnect");
|
||||
btnAdminConnect->SetText(L"🔄");
|
||||
btnAdminConnect->Style.BackColor = Color(0, 185, 107);
|
||||
}
|
||||
else if (btnName == "btnAdminTemp") { //管理页面的测试按钮
|
||||
TextBox* textAdmin = (TextBox*)FindControl("textAdminOutput"); //获取输出框
|
||||
if (textAdmin) {
|
||||
textAdmin->Insert(L"\n测试成功!",true);
|
||||
textAdmin->GetScrollBar()->ScrollTo(1.0);
|
||||
}
|
||||
|
||||
TableView* tableView = (TableView*)FindControl("tableViewAdmin"); //获取表格控件
|
||||
if (tableView) {
|
||||
tableView->SetColumnType(4, ezui::CellType::CheckBox);
|
||||
tableView->SetColumnType(5, ezui::CellType::ComboBox);
|
||||
tableView->SetColumnComboItems(5, {L"选择1", L"选择2"});
|
||||
tableView->InsertRow(1);
|
||||
tableView->SetRowData(tableView->GetRowCount() - 1, {L"uid1", L"192.168.200.131"});
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ezui::OnMouseDoubleClick: //鼠标双击
|
||||
{
|
||||
//if (btnName == "titleMain") { //标题布局
|
||||
// if (this->IsMaximized()) {
|
||||
// this->ShowNormal();
|
||||
// }
|
||||
// else {
|
||||
// this->ShowMaximized();
|
||||
// }
|
||||
//}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (args.EventType == Event::OnMouseDown) {
|
||||
|
||||
|
||||
}
|
||||
__super::OnNotify(sender, args);
|
||||
}
|
||||
|
||||
void mainForm::OnClose(bool& close)
|
||||
{
|
||||
Application::Exit();
|
||||
}
|
||||
|
||||
mainForm::mainForm() :LayeredWindow(1000, 750)
|
||||
{
|
||||
SetResizable(true); // 启用窗口大小调整
|
||||
SetMiniSize(Size(600, 450)); // 设置最小尺寸
|
||||
umg.LoadXml("res/mainForm.htm");//加载xml里面的控件与样式
|
||||
umg.SetupUI(this);
|
||||
}
|
||||
|
||||
mainForm::~mainForm()
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user