Post MouseUp 更改数据网格!

发布于 2024-08-24 03:59:48 字数 896 浏览 4 评论 0原文

我有 .NET CF 应用程序,其中包含一个数据网格,我使用主要源自本文的解决方案将其绑定到 BindingList:http://msdn.microsoft.com/en-us/library/aa480736.aspx

我已将其连接起来,以便单击列标题时,我获取 HitTest 信息并检查类型。如果类型是 ColumnHeader,那么我会在基础 BindingList 上启动排序(使用与上面发布的链接中的示例类似的代码),这反过来又使 DataGrid 根据我单击的 T 的属性对自身进行排序。例如描述

这绝对没问题!

当我现在单击数据网格时,问题就出现了 - 假设我有两行,执行排序后,没有选择任何行。我单击第 1 行中的一个单元格,我有选择整行的代码 - 发生此操作并且一切正常。当我现在单击第 2 行时,第 2 行被选中并且一切正常,网格仍然应用了我的排序。如果我现在再次单击第 1 行,我的排序就会相反,但最重要的是,“ApplySort”方法实际上并未被调用。那么到底发生了什么?仅当我单击第 1 行时才会发生这种情况,网格中的两行实际上是相反的。选择第 2 行时,不会发生这种情况。

调试时,我可以看到 mousedown 触发(我在其中放入了 return; 语句),然后 MouseUp 触发,如果列标题已被单击,则执行 HitTest 并调用 ApplySort(在本例中没有单击)。我注意到排序的变化发生在 * AFTER * 控件离开 MouseUp 事件之后 - 所以在 MouseDown/MouseUp 完成后,某个地方的某些东西似乎正在改变我的网格状态。

有什么想法可能会扰乱我的网格吗?我基本上想知道,一旦我调用了 ApplySort,我是否可以抑制任何其他内容。

I have .NET CF app, with a form that contains a datagrid which I've bound to a BindingList using a solution derived mainly from this article: http://msdn.microsoft.com/en-us/library/aa480736.aspx

I've hooked it up so that when a column header is clicked, I get the HitTest information and check for the Type. If the Type is ColumnHeader, then I initiate a Sort on the underlying BindingList (Using code similar to the example in the link posted above) - which in turn, makes the DataGrid sort itself according to the Property of T that I have clicked. E.g. Description

This works absolutely fine!

The problem comes when I now click around my datagrid - Let's say I have two rows, after the sort is performed, no row is selected. I click a cell in row 1 and I have code that selects the whole row - this operations occurs and all is well. When I now click row 2, row 2 gets selected and all is well, grid still has my sort applied. If I now click row 1 again, my sorting gets reversed, but crucially, the "ApplySort" method is not actually being called. So what is happening? It only happens when I click row 1, the two rows in the grid effectively are reversed. On selecting row 2, it does not occur.

Upon debugging, I can see that mousedown fires (which i have put a return; statement in) and then MouseUp fires, which does the HitTest and calls ApplySort if the columnheader has been clicked, which in this case it has not. I noticed that the change in sort occurs * AFTER * control has left the MouseUp event - so something, somewhere, seems to be altering my grid state after MouseDown/MouseUp have finished.

Any ideas what event/action could be messing with my Grid? I basically want to know if I can suppress anything and everything else once I have called my ApplySort.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

两人的回忆 2024-08-31 03:59:48

我不期望对此有很多答案......但我刚刚注意到这种行为仅当要排序的列包含彼此相同的值时才会发生。

数据不同的列,不会发生该行为。

所以我想这很可能是设计使然 - 我应该使实现不那么通用并根据特定的 id 属性进行排序,该属性包含不同的值,而不是根据用户单击的内容动态对列进行排序 - 因为这很可能具有我已经描述过的副作用。

I don't expect many answers to this...but I have just noticed that this behaviour ONLY occurs when the column to sort contains values which are identical to one another.

Columns where the data is different, the behaviour does not occur.

So I suppose this might well be by design - I should make the implementation less generic and sort on a particular id property, which contains distinct values, rather than sort the columns dynamically based on what the user clicked on - as this may well have the side-effect that i've described.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文