gpt4 book ai didi

c# - 按下箭头键时不触发文本框 Keydown 事件

转载 作者:可可西里 更新时间:2023-11-01 07:51:46 26 4
gpt4 key购买 nike

我有一个数据网格,其中一列作为 DataGridTemplateColumn,如下所示:

<my:DataGrid Name="dgvSales"   RowHeight="23"  SelectionUnit="Cell"  BeginningEdit="dgvSales_BeginningEdit"  AutoGenerateColumns="False"   CellEditEnding="dgvSales_CellEditEnding" >
<my:DataGrid.Columns>
<my:DataGridTemplateColumn Header="Product Name" Width="200">
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Product_Name}"></TextBlock>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
<my:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox x:Name="txtbxProduct" Text="{Binding Product_Name}" TextChanged="txtbxProduct_TextChanged" KeyDown="txtbxProduct_KeyDown"></TextBox>
</DataTemplate>
</my:DataGridTemplateColumn.CellEditingTemplate>
</my:DataGridTemplateColumn>
</my:DataGrid.Columns>
</my:DataGrid>

当单元格值发生变化时,我想将一些项目填充到 ListView 中,TextChanged 事件如下:

 private void txtbxProduct_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox tb = (TextBox)sender;
if (tb.Text.Trim() != "")
{
string qry = "select PL.Record_Id as PList_Id,PM.Record_Id as Product_Id,PM.Product_Code,PM.Product_Name,PTM.Product_Type,PL.Purchase_Rate ,PL.Selling_Rate,PL.MRP from dbo.Tbl_Product_Master PM join Tbl_Product_List PL on PL.Product_Id=PM.Record_Id join Tbl_Product_Type_Master PTM on PTM.Record_Id=PM.Product_Category_Id where PL.Batch_Flag=0 and PM.Is_Del='false'and PM.Is_Active='true' and PM.Product_Name like '%" + tb.Text.Trim() + "%' order by PM.Product_Name ";
DataSet ds = ObjCommon.GetObject.ExecuteQuery_Select(Connection.ConnectionString, qry);
if (ds.Tables[0].Rows.Count > 0)
{
lstvwProductCode.ItemsSource = ds.Tables[0].DefaultView;
lstvwProductCode.Visibility = Visibility.Visible;
}
else
{
lstvwProductCode.ItemsSource = null;
lstvwProductCode.Visibility = Visibility.Collapsed;
}
}
else
{
lstvwProductCode.ItemsSource = null;
lstvwProductCode.Visibility = Visibility.Collapsed;
}
}

当用户在键盘上输入向下键时,我想专注于 ListView ,但当我按下、返回、空格等键时,它不会触发 Keydown 事件,但其他键(如字母数字键)都可以正常工作。我的按键事件如下:

private void txtbxProduct_KeyDown(object sender, KeyEventArgs e)
{
TextBox tb = (TextBox)sender;
if (e.Key == Key.Escape)
{
tb.Clear();
lstvwProductCode.Visibility = Visibility.Collapsed;
tb.Focus();
}
else if (e.Key == Key.Down)
{
if (lstvwProductCode.Items.Count > 0)
{
lstvwProductCode.SelectedIndex = 0;
lstvwProductCode.Focus();
lstvwProductCode.Visibility = Visibility.Visible;
}
}
}

我的代码哪里做错了?

最佳答案

而不是使用 PreviewKeyDown

关于c# - 按下箭头键时不触发文本框 Keydown 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18931399/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com