Skip to content

Commit

Permalink
🔥 优化编辑表、列注释时编辑框的宽度与单元格宽度相同
Browse files Browse the repository at this point in the history
  • Loading branch information
zfluok committed Mar 30, 2023
1 parent 932f8a8 commit 165919f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions SmartSQL/SmartSQL/UserControl/Main/UcMainColumns.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
CellEditEnding="TableGrid_OnCellEditEnding"
Cursor="Arrow"
HeadersVisibility="All"
PreparingCellForEdit="TableGrid_OnPreparingCellForEdit"
ItemsSource="{Binding ObjectColumns}"
RowHeaderWidth="60"
SelectedCellsChanged="TableGrid_OnSelectedCellsChanged"
Expand Down
16 changes: 16 additions & 0 deletions SmartSQL/SmartSQL/UserControl/Main/UcMainColumns.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,28 @@ private void TableGrid_OnBeginningEdit(object sender, DataGridBeginningEditEvent
if (selectedData is TextBlock)
{
var selectedText = (TextBlock)selectedData;
selectedText.Width = 420;
_cellEditValue = selectedText.Text;
}
}
#endregion
}

/// <summary>
/// 单元格编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TableGrid_OnPreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs e)
{
if (e.EditingElement != null && e.EditingElement is TextBox)
{
var cell = (DataGridCell)e.EditingElement.Parent;
//设置单元格中的TextBox宽度
e.EditingElement.Width = cell.ActualWidth - 10;
}
}

/// <summary>
/// 单元格修改提交
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions SmartSQL/SmartSQL/UserControl/Main/UcMainObjects.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
ItemsSource="{Binding ObjectsViewData, Mode=TwoWay}"
MouseDoubleClick="TableGrid_OnMouseDoubleClick"
MouseLeftButtonUp="TableGrid_OnMouseLeftButtonUp"
PreparingCellForEdit="TableGrid_OnPreparingCellForEdit"
RowHeaderWidth="60"
SelectionUnit="CellOrRowHeader">
<!--<DataGrid.CellStyle>
Expand Down
15 changes: 15 additions & 0 deletions SmartSQL/SmartSQL/UserControl/Main/UcMainObjects.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,21 @@ private void TableGrid_OnBeginningEdit(object sender, DataGridBeginningEditEvent
}
}

/// <summary>
/// 单元格编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TableGrid_OnPreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs e)
{
if (e.EditingElement != null && e.EditingElement is TextBox)
{
var cell = (DataGridCell)e.EditingElement.Parent;
//设置单元格中的TextBox宽度
e.EditingElement.Width = cell.ActualWidth - 10;
}
}

private void TableGrid_OnCellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
#region MyRegion
Expand Down

0 comments on commit 165919f

Please sign in to comment.