将焦点设置在 WPF DataGridTextColumn 上时出现问题
我有如下所示的 WPF DataGrid:
<DataGrid x:Name="MasterMemlinesDataGrid"
ItemSources= "{Binding MyItems}"
SelectedItem= "{Binding SelectedItem}">
<DataGrid.Columns>
<DataGridTextColumn Width="110" x:Name="ItemCodeTextColumn"
Binding="{Binding ItemCode}" />
<DataGridTextColumn Width="110" x:Name="ItemDescTextColumn"
IsReadOnly="True" Binding="{Binding ItemDescription}" />
<DataGridTextColumn Width="110" x:Name="ItemManiDescTextColumn"
Binding="{Binding ItemMainDescription}" />
</DataGrid.Columns>
</DataGrid>
我还有一个按钮,可以打开视图并显示项目列表。用户选择一个项目后,我将更新“ItemCodeTextColumn”和“ItemDescTextColumn”以显示所选项目,然后将焦点设置到“ItemManiDescTextColumn”单元格。谁能告诉我如何将焦点设置到“ItemManiDescTextColumn”单元格?
谢谢
I have WPF DataGrid like below:
<DataGrid x:Name="MasterMemlinesDataGrid"
ItemSources= "{Binding MyItems}"
SelectedItem= "{Binding SelectedItem}">
<DataGrid.Columns>
<DataGridTextColumn Width="110" x:Name="ItemCodeTextColumn"
Binding="{Binding ItemCode}" />
<DataGridTextColumn Width="110" x:Name="ItemDescTextColumn"
IsReadOnly="True" Binding="{Binding ItemDescription}" />
<DataGridTextColumn Width="110" x:Name="ItemManiDescTextColumn"
Binding="{Binding ItemMainDescription}" />
</DataGrid.Columns>
</DataGrid>
Also I have a button which open a view and displays a list of item. After user selects a item, I will update the "ItemCodeTextColumn" and "ItemDescTextColumn" to display the select item, then set focus to the "ItemManiDescTextColumn" cell. Can anyone let me know how I can set the focus to the "ItemManiDescTextColumn" cell?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设你有一行 &对于该单元格的列索引,Artur 有一些数据网格扩展方法,可以从行和行中获取单元格。列索引。获得单元格后,您只需调用单元格焦点方法即可。
http://techiethings.blogspot.com/2010 /05/get-wpf-datagrid-row-and-cell.html
如果您不知道列索引但知道列,则可以使用 DataGrid.Columns.IndexOf( ItemManiDescTextColumn ) 找到它的索引
Assuming you have a row & column index for this cell, Artur has some datagrid extension methods that get a cell from a row & column index. Once you have the cell you just call the cells focus method.
http://techiethings.blogspot.com/2010/05/get-wpf-datagrid-row-and-cell.html
If you don't know the column index but do know the column, you could find it's index using DataGrid.Columns.IndexOf( ItemManiDescTextColumn )