优化单元格进入编辑状态后,能跟随区域移动
This commit is contained in:
@@ -77,7 +77,14 @@ void mainForm::OnNotify(Control* sender, EventArgs& args)
|
||||
// 表格增加一行数据
|
||||
tableView->InsertRow(rowCount);
|
||||
tableView->SetRowData(rowCount, { L"uid" + std::to_wstring(rowCount), L"192.168.200.131\n127.0.0" , L"", L"2026-02-25"});
|
||||
// 获取表格指定位置数据
|
||||
tableView->SetCellChecked(rowCount, 5, true);
|
||||
tableView->SetCellComboIndex(rowCount, 2, 0);
|
||||
|
||||
// 改变单元格颜色
|
||||
/*CellStyle style = tableView->GetCellStyle(1, 1);
|
||||
style.SetBackColor(Color(200, 230, 155));
|
||||
tableView->SetCellStyle(1, 1, style);*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +118,7 @@ void mainForm::OnClose(bool& close)
|
||||
Application::Exit();
|
||||
}
|
||||
|
||||
mainForm::mainForm() :LayeredWindow(1000, 750)
|
||||
mainForm::mainForm() :LayeredWindow(1400, 750)
|
||||
{
|
||||
SetResizable(true); // 启用窗口大小调整
|
||||
SetMiniSize(Size(600, 450)); // 设置最小尺寸
|
||||
@@ -128,17 +135,16 @@ mainForm::mainForm() :LayeredWindow(1000, 750)
|
||||
TableView* tableView = (TableView*)FindControl("tableViewAdmin"); //获取表格控件
|
||||
if (tableView) {
|
||||
tableView->SelectedRowBackColor = Color(200, 230, 255); // 设置选中行背景色
|
||||
tableView->SetColumnType(5, ezui::CellType::CheckBox);
|
||||
//tableView->SetColumnType(5, ezui::CellType::CheckBox);
|
||||
tableView->SetColumnType(2, ezui::CellType::ComboBox);
|
||||
tableView->SetColumnComboItems(2, { L"默认", L"禁止" , L"验机" });
|
||||
tableView->SetDefaultTextAlign(Align::MiddleCenter);
|
||||
|
||||
//设置列宽
|
||||
std::vector<int> withs = {60, 120, 50, 90, 85, 85, 100, 70, 70, 80, 80, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90};
|
||||
for(auto i=0;i< withs.size();i++)
|
||||
for(int i = 0; i < withs.size(); i++)
|
||||
tableView->SetColumnWidth(i, withs[i]);
|
||||
|
||||
|
||||
// 鼠标右键单击的回调
|
||||
tableView->RightClick = [tableView](int row, int col) {
|
||||
int pRow = tableView->GetHoverRow(); //当前行号
|
||||
@@ -150,7 +156,7 @@ mainForm::mainForm() :LayeredWindow(1000, 750)
|
||||
|
||||
// 单元格编辑完成(编辑结束时触发,提供旧值与新值)
|
||||
tableView->CellEditFinished = [](int row, int col, const UIString& oldValue, const UIString& newValue) {
|
||||
std::cout << "单元格内容: " << newValue.ansi() << ", " << oldValue.ansi() << std::endl;
|
||||
std::cout << "完成编辑单元格内容: " << newValue.ansi() << ", " << oldValue.ansi() << std::endl;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -730,11 +730,35 @@ namespace ezui {
|
||||
|
||||
void TableView::OffsetX(int offset) {
|
||||
m_scrollOffsetX = -offset;
|
||||
|
||||
// 如果正在编辑,更新编辑框位置
|
||||
if (m_editing && m_editBox->IsVisible() && m_editRow >= 0 && m_editCol >= 0) {
|
||||
if (m_editCol < (int)m_columns.size() && m_editRow < (int)m_rowHeights.size()) {
|
||||
int x = GetColumnX(m_editCol);
|
||||
int y = GetRowY(m_editRow);
|
||||
int width = m_columns[m_editCol].Width;
|
||||
int height = m_rowHeights[m_editRow];
|
||||
m_editBox->SetRect(Rect(x, y, width, height));
|
||||
}
|
||||
}
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
void TableView::OffsetY(int offset) {
|
||||
m_scrollOffsetY = -offset;
|
||||
|
||||
// 如果正在编辑,更新编辑框位置
|
||||
if (m_editing && m_editBox->IsVisible() && m_editRow >= 0 && m_editCol >= 0) {
|
||||
if (m_editCol < (int)m_columns.size() && m_editRow < (int)m_rowHeights.size()) {
|
||||
int x = GetColumnX(m_editCol);
|
||||
int y = GetRowY(m_editRow);
|
||||
int width = m_columns[m_editCol].Width;
|
||||
int height = m_rowHeights[m_editRow];
|
||||
m_editBox->SetRect(Rect(x, y, width, height));
|
||||
}
|
||||
}
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user