将已排序的数据网格中的当前单元格(行,列)转换为数据表中的相应行/列 [英] translate current cell (row, column) in sorted datagrid to corresponding row/col in datatable

查看:60
本文介绍了将已排序的数据网格中的当前单元格(行,列)转换为数据表中的相应行/列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表作为数据网格的数据源。 datagrid定义了一个

datagridtablestyle。我使用datagridtablestyle来更改列的

顺序(因此它们可能与

数据表的列顺序不同)。我还允许用户单击列标题以按该列对

数据网格进行排序。


我需要识别数据表中的行和列当用户在数据网格中的单元格上单击

时。

使用datagrid.HitTestInfo我可以很容易地找到
的行和列
datagrid(即:hti.row和hti.column)。现在我需要找到用户在实际的

数据表中单击的单元格的相应行和列的

。我需要在MOUSEDOWN事件中执行此操作。


作为初步想法,我使用Dim bm作为BindingManagerBase,如下所示:


bm = Me.dg.BindingContext(Me.dg.DataSource)


但是,似乎ctype访问的数据行(bm.current,

datarowview)指向用户点击鼠标之前的行

新单元格。在更新

bm.current行之前,mousedown事件似乎已得到控制。


无论如何,这一切都意味着我现在完全感到困惑。显然必须将数据网格行/列转换为数据表

行/列,因为您可以重新排列列并将它们排序到您的心中


内容,当你随后更改数据网格中单元格的值时,它会更新数据表中正确的行/列。它是如何做的???


是否有某种函数或公式将返回给定datagrid行的数据表

行/列柱???像

这样的东西会很棒:RowInDatatable = ConvertToDataTableRow(RowInDataGrid)。


我会很感激任何指导。

谢谢,John

I have a datatable as the datasource to a datagrid. The datagrid has a
datagridtablestyle defined. I use the datagridtablestyle to change the
order of the columns (so they can be different than the column order of the
datatable). I also allow the user to click on a column header to sort the
datagrid by that column.

I need to identify the row and column in the datatable when the user clicks
on a cell in the datagrid.

Using the datagrid.HitTestInfo I can easily find out the row and column of
the datagrid (ie: hti.row and hti.column). Now I need to find the
corresponding row and column for the cell the user clicked on in the actual
datatable . I need to do this in the MOUSEDOWN event.

As an initial thought, I used a Dim bm as BindingManagerBase like this:

bm = Me.dg.BindingContext(Me.dg.DataSource)

However, it seems that the datarow accessed by ctype(bm.current,
datarowview) points to the row just before the user clicked the mouse on
the new cell. The mousedown event seems to take control before the
bm.current row is updated.

Anyway, all this means that I am now totally confused. Clearly there must
be a procedure to translate the datagrid row/column to the datatable
row/column because you can rearrange columns and sort them to your hearts
content, and when you then change the value of a cell in the datagrid, it
updates the proper row/column in the datatable. SO HOW DOES IT DO IT???

Is there some sort of function or formula that will return the datatable
row/column given the datagrid row/column??? It would be great to have
something like: RowInDatatable = ConvertToDataTableRow(RowInDataGrid).

I would appreciate any guidance on this.
Thanks, John


推荐答案

John,


每个数据表有一个默认视图。 (数据视图)。那是Sort

属性。当没有用于显示数据表的额外数据视图时,使用默认视图是




因此,您可以在sort属性中看到哪个列和在什么

订单中它被排序。


它自己的数据表没有按顺序排序。


我希望这会有所帮助,


Cor
John,

Every datatable has a defaultview. (A dataview). In that is the Sort
property. When there is no extra dataview used to show the datatable, than
that defaultview is used.

Therefore you can than see in the sort property which column and in what
order it is sorted.

The datatable it self is not sorted by the way.

I hope this helps,

Cor


您好Cor,


那么如何这会帮助我将datagrid单元格坐标转换为

数据表坐标吗?请记住,数据网格中的列也可以是

切换(通过datagridtablestyle)。


John


Cor Ligthert <无************ @ planet.nl>在消息中写道

news:%2 **************** @ TK2MSFTNGP15.phx.gbl ...
Hi Cor,

So how would that help me to translate datagrid cell coordinates to the
datatable coordinates? Remember, the columns in the datagrid may be
switched also (via the datagridtablestyle).

John

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
John,

每个数据表都有一个默认视图。 (数据视图)。那就是Sort
属性。当没有用于显示数据表的额外数据视图时,使用的是defaultview视图。

因此,您可以在sort属性中查看哪个列以及在什么位置对它进行排序排序。

它自己的数据表不按顺序排序。

我希望这有帮助,

Cor
John,

Every datatable has a defaultview. (A dataview). In that is the Sort
property. When there is no extra dataview used to show the datatable, than
that defaultview is used.

Therefore you can than see in the sort property which column and in what
order it is sorted.

The datatable it self is not sorted by the way.

I hope this helps,

Cor



John,


只需使用debuging快速查看table.defaultview.sort

查看,而不是看到它究竟是如何发生的。假设这是来自数据网格的

数据源。

http://msdn.microsoft.com/library/de...ssorttopic.asp


我希望这会有所帮助,


Cor
John,

Just have a look at the table.defaultview.sort using debuging and quick
view, than you see exactly how it happens. Assuming that that is the
datasource from your datagrid.

http://msdn.microsoft.com/library/de...ssorttopic.asp

I hope this helps,

Cor


这篇关于将已排序的数据网格中的当前单元格(行,列)转换为数据表中的相应行/列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆