VB6 MSFlexGrid - 合并列的 ColPos

发布于 2024-09-14 21:57:40 字数 786 浏览 11 评论 0原文

我正在 VB6 中使用 MSFlexGrid 控件,但在检索合并列的 ColPos 属性时也遇到一些问题。我生成的网格看起来像这样:

-----------------------------
|         8/17/2010         |
-----------------------------
|   Column 1  |  Column 2   |
-----------------------------

第一行是固定的,两列被合并,因此两列在第一行中都包含 8/17/2010

Click 事件期间,我将文本框放置在第二行中的单元格上,并且当我设置其 LeftTop 属性时使用 FlexGrid 的 ColPosRowPos 属性,我最终将文本框定位在第 1 列上方。即使我单击第 2 列,也会发生这种情况

我检查了 Col 属性,单击第二列后它正确设置为 2,但是 ColPos(1)ColPos(2) 都返回相同的值,即从第 1 列左边缘到控件左边缘的距离。

当在 FlexGrid 上禁用合并时,问题就会消失,但我宁愿保留它,因为它使网格更具可读性。

当列中的另一个单元格与另一个单元格合并时,有什么方法可以检索所选列的正确位置,或者我是否需要手动计算列位置?

I'm working with a MSFlexGrid control in VB6, but I'm also having some problems retrieving the ColPos property for merged columns. The grid that I've generated looks something like this:

-----------------------------
|         8/17/2010         |
-----------------------------
|   Column 1  |  Column 2   |
-----------------------------

The first row is fixed and the two columns are merged, so both columns contain 8/17/2010 in the first row.

During the Click event, I'm positioning a text box over a cell in the second row, and when I set its Left and Top properties using the FlexGrid's ColPos and RowPos properties, I end up with the textbox positioned over column 1. This happens even if I clicked in column 2.

I've checked the Col property, and it's correctly set to 2 after clicking in the second column, but ColPos(1) and ColPos(2) both return the same value, which is the distance from column 1's left edge to the left edge of the control.

When merging is disabled on the flexgrid, the problem goes away, but I'd rather leave it on since it makes the grid a bit more readable.

Is there any way to retrieve the correct position of the selected column when another cell in the column is merged with another one, or do I need to calculate the column position manually?

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

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

发布评论

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

评论(1

遗忘曾经 2024-09-21 21:57:40

还没有找到通过控件来完成此操作的方法,但这是我组合在一起的一个函数,可以实现这一点。它从选定的单元格开始向后计数,直到到达与其合并的最左边的单元格,然后将合并单元格的宽度添加到第一个单元格的位置。可能可以清理一些,但这确实有效。

Private Function RealColPos(Col As Integer, grid as MSFlexGrid)

    With grid

        Dim i As Integer, merged As Integer

        i = Col - 1: merged = 0
        Do While .ColPos(Col) = .ColPos(i)
            merged = merged + 1
            i = i - 1
        Loop

        If merged > 0 Then
            RealColPos = .ColPos(Col - merged)
            Do While merged > 0
                RealColPos = RealColPos + .ColWidth(Col - merged)
                merged = merged - 1
            Loop
        Else
            RealColPos = .ColPos(Col)
        End If

    End With

End Function

Haven't found a way to do it through the control, but here's a function that I put together that does the trick. It counts backward from the selected cell until it reaches the leftmost cell it's merged with, and then adds the widths of the merged cells to the first one's position. Probably could be cleaned up some, but this does work.

Private Function RealColPos(Col As Integer, grid as MSFlexGrid)

    With grid

        Dim i As Integer, merged As Integer

        i = Col - 1: merged = 0
        Do While .ColPos(Col) = .ColPos(i)
            merged = merged + 1
            i = i - 1
        Loop

        If merged > 0 Then
            RealColPos = .ColPos(Col - merged)
            Do While merged > 0
                RealColPos = RealColPos + .ColWidth(Col - merged)
                merged = merged - 1
            Loop
        Else
            RealColPos = .ColPos(Col)
        End If

    End With

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