This commit is contained in:
sc committed 2024-09-04 22:25:46 +08:00
commit 21eac08f7a
4 files changed
+41 -12

No files matched your search

+2 -3
View File
@@ -6,7 +6,7 @@
xmlns:local="clr-namespace:DyeingComputer.View"
xmlns:lang="clr-namespace:DyeingComputer.Properties"
xmlns:localUserClass="clr-namespace:DyeingComputer.UserClass"
mc:Ignorable="d"
mc:Ignorable="d" Loaded="UserControl_Loaded"
d:DesignHeight="630" d:DesignWidth="1280" VerticalAlignment="Top">
<Grid>
<DataGrid x:Name="Grid" AlternationCount="2" Margin="0,0,0,0" d:ItemsSource="{d:SampleData ItemCount=99}" AutoGenerateColumns="False"
@@ -14,8 +14,7 @@
BorderThickness="1,1,1,1" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" Grid.ColumnSpan="2" AllowDrop="False"
CanUserReorderColumns="False" CanUserSortColumns="False" CanUserResizeRows="False" CanUserResizeColumns="False"
CanUserAddRows="False" CanUserDeleteRows="False" HeadersVisibility ="Column" InputMethod.IsInputMethodEnabled ="False"
CellEditEnding="Grid_CellEditEnding"
Background="White" SelectionMode="Single" FontSize="15" Cursor="AppStarting" >
CellEditEnding="Grid_CellEditEnding" Background="White" SelectionMode="Single" FontSize="15" Cursor="AppStarting" >
<DataGrid.RowStyle >
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Height" Value="30" />
+30 -8
View File
@@ -32,12 +32,6 @@ namespace DyeingComputer.View
{
InitializeComponent();
set_sql();
//Grid.Focus();
Grid.SelectedIndex = 0;
// var row = Grid.ItemContainerGenerator.ContainerFromIndex(0) as FrameworkElement;
//if (row != null ) {row.Focus(); }
}
private SQLiteHelper SQLiteHelpers = null; //定义数据库
@@ -65,16 +59,44 @@ namespace DyeingComputer.View
int rownum = Grid.SelectedIndex;//获取鼠标选中行并定义变量
if (rownum != -1)//判断鼠标定位是否有效
{
{
ID = (Grid.Columns[1].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第0列,
Dictionary<string, object> datagrid_v = new Dictionary<string, object>();//缓存函数
datagrid_v.Add("Value", newValue);
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
SQLiteHelpers.Update("Parameters",datagrid_v , "ParameterID ='"+ ID + "'", null);//更新
SQLiteHelpers.Update("Parameters", datagrid_v, "ParameterID ='" + ID + "'", null);//更新
SQLiteHelpers.Close();//关闭数据库
}
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)//打开页面时的操作
{
DataGridRow dr = (DataGridRow)Grid.ItemContainerGenerator.ContainerFromIndex(0);//取第0行单元格
DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(dr);
DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(3); //取第3列每行单元格
cell.Focus();
Grid.SelectedIndex = 0;
}
public static T GetVisualChild<T>(Visual parent) where T : Visual
{
T child = default(T);
int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < numVisuals; i++)
{
Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
child = v as T;
if (child == null)
{
child = GetVisualChild<T>(v);
}
if (child != null)
{
break;
}
}
return child;
}
}
}