简体   繁体   English

如何:使用多个DataGridViews进行单选

[英]How to: Single Selection with Multiple DataGridViews

I am pulling records from a SQL database via LINQ and displaying the entries in two separate DataGridViews. 我正在通过LINQ从SQL数据库中提取记录,并在两个单独的DataGridViews中显示条目。 I'm wondering what is the best way to allow only one row to be selected between the two components? 我想知道在两个组件之间只选择一行的最佳方法是什么?

For example: If A, B, and C are stored in DGV1. 例如:如果A,B和C存储在DGV1中。 And D, E, and F are stored in DGV2. D,E和F存储在DGV2中。 Only A, B, C, D, E, or F can be selected at a time. 一次只能选择A,B,C,D,E或F。

What I've tried so far: Using the SelectionChanged event for each DGV to call ClearSelection() in the other DGV. 到目前为止,我已经尝试过:对每个DGV使用SelectionChanged事件在另一个DGV中调用ClearSelection()。 Obviously this was a horrible idea since it is essentially an infinite loop. 显然,这是一个可怕的想法,因为它本质上是一个无限循环。 I also tried playing around with the CellClick event but it would not account for users changing selection via up/down keys. 我也尝试过使用CellClick事件,但是它不能说明用户通过向上/向下键更改选择的情况。

Any help is greatly appreciated and please let me know if any extra info is needed. 非常感谢您的帮助,如果需要任何其他信息,请告诉我。

Don't call ClearSelection() for the other grid in the SelectionChanged event if nothing is selected. 如果未选择任何内容,则不要在SelectionChanged事件中为另一个网格调用ClearSelection() ie If (changedGrid.SelectedRows.Count > 0) {OtherGrid.ClearSelection();} If (changedGrid.SelectedRows.Count > 0) {OtherGrid.ClearSelection();}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在2个DataGridViews中选择多行 - How to select multiple rows in 2 DataGridViews 从单个二维数组填充多个datagridviews - Populating multiple datagridviews from a single 2 dimensional array 单击一次即可刷新多个datagridviews - Refreshing multiple datagridviews with single button click 1个表单上的多个DataGridViews - Multiple DataGridViews on 1 Form 将数据从表单上的多个DataGridView导出到单个Excel文件中的多个Excel工作表 - Exporting Data From Multiple DataGridViews on a Form to Multiple Excel Sheets in a Single Excel File 在一个脚本中处理多个DataGridViews? - Handle Multiple DataGridViews In one Script? 将ContextMenuStrips添加到多个TabPages上的多个DataGridViews - Add ContextMenuStrips to multiple DataGridViews on multiple TabPages 如何在DataGridViews中同步水平滚动 - How to synchronise horizontal scrolling in DataGridViews 如何对多个DataGridView使用相同的DataSource,并对每个DataGridView应用不同的过滤器? - How can I use the same DataSource for multiple DataGridViews with a different filter applied on each? C#如何在Winrt的gridview中将单个选择绑定到多个选择? - C# How make a single selection binding to a multiple selection in a gridview on winrt?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM