有没有办法将数据与未显示给用户的MSFlexGrid单元格相关联?

时间:2015-05-20 23:25:10

标签: vb6

说我有你的标准MSFlexGrid。我在已经有工具提示的单元格中有一个图像。

我想要做的是在单元格中存储关于图像的字符串,该字符串与单元格关联但不显示给最终用户。

我一直在查看MSDN网站上的属性,但我没有看到任何可行的内容。

这可能吗?以前有人做过类似的事吗?我并不反对在这种意义上使用不一定用于数据存储的属性,只要它们尚未被使用,但显然这是不可取的。

1 个答案:

答案 0 :(得分:0)

所以这就是我为那些可能想要做同样事情的人所做的。它不优雅,它不漂亮,但它有效。

Private m_colImageInfo As Collection ' dictionary to store image name Key="Index^m_Tracker Row^Column" Value=IconKey
Private m_colImageInfoSorted As Collection ' Dictionary to store image name Key="Index^FG Row^Column" Value=IconKey
Private m_colSortRowInfo As ACCollection ' How the row changes

我有一个名为DoDisplay()的函数,每次刷新或最初显示网格时都会调用它。

在其中,我清除了m_colSortRowInfo集合(ACCollection只是我们构建的包装器)。

  Call m_colSortRowInfo.Clear ' Note ACCollection allows the use of Clear

现在进行显示我们从模型中抓取数据,并通过第一次DoAction调用获取实际图像,然后通过第二次调用获取图像密钥(图像的唯一标识符)。

Set oImage = m_Tracker2.DoAction(TS_ACTION_GET_COL_ICON, lRow, lColumn, False)  'Retrieve the icon image ' get the image
                      sString = m_Tracker2.DoAction(TS_ACTION_GET_COL_ICON, lRow, lColumn, True)
                      If Len(sString) > 0 Then
                        On Error Resume Next
                        Call m_colSortRowInfo.Add(CStr(.Index & "^" & lRow & "^" & .Col)) ' lets store the old key as a value for later access
                        Call m_colImageInfo.Add(sString, CStr(.Index & "^" & lRow & "^" & .Col))
                        On Error GoTo 0
                      End If

然后我将图标键添加到m_colImageInfo作为Collection"" item"并且关键是网格索引^ m_TrackerRow ^列。

对于m_colSortRowInfo,我将相同的值(Index ^ m_TrackerRow ^ Column)设置为项目,然后键只是一个简单的迭代索引。

现在我遇到的问题是这些图像存在于网格中,但除了单元格包含或不包含图像/文本之外,我对它们一无所知。我需要将图标键与图像相关联,原因与此帖无关。

现在,我们已经获得了图像所在模型的网格,行和列,但我们并不知道它在网格中的实际位置。列保持不变,但根据用户对网格的排序方式,行可以更改。这是关键的挑战。

我们可以将模型网格行映射到特定的MSFlexGrid行。我在下面的方法中使用它来填充m_colImageInfoSorted,这是网格中每个图像的实际表示。

'------------------------------------------------------------------
' NAME:         SortImageCollection (PRIVATE)
' DESCRIPTION:  When we first create the flex grid we pull the images from
'               the image provider service and scale them up unfortunately there is
'               no reference to the image that gets back. So what we do is create a
'               collection to keep track of the image location and then send it to
'               the printing class. If the grid has been sorted however, we need to
'               identify where that picture moved too. This sub serves that purpose.
' KEYWORDS:     sort, icon, collection, image
' CALLED BY:    DoDisplay
' PARAMETERS:
'  Index (I,REQ) - FlexGrid index
' RETURNS:      nothing
' ASSUMES:
' SIDE EFFECTS: populates m_colImageInfoSorted with image keys in the fg grid
'               with index passed to the function
'------------------------------------------------------------------
Private Sub SortImageCollection(Index As Integer)
  Dim lCnt As Long
  Dim lNumImages As Long
  Dim lColumn As Long
  Dim lRow As Long
  Dim lOldRow As Long
  Dim lCurGrid As Long
  Dim sTempIconStr As String
  Dim sOldKey As String
  Dim sNewKey As String

  Set m_colImageInfoSorted = Nothing
  Set m_colImageInfoSorted = New Collection

  With fgFlexGrid(Index)
    For lNumImages = 1 To m_colSortRowInfo.Count                                        ' we will loop over all the images
      lCurGrid = CLng(Piece(m_colSortRowInfo.ItemVar(lNumImages), "^", 1, False))          ' if the grid is the grid we we asked for, then continue
      If (lCurGrid = Index) Then                                                        ' we are just sorting images for this grid
        For lCnt = 1 To m_lPatientRows(Index)
          On Error Resume Next
          lOldRow = CLng(Piece(m_colSortRowInfo.ItemVar(lNumImages), "^", 2, False))       ' get the m_tracker row we stored earlier
          lRow = getRowFromFlexGrid(Index, lCnt)                                        '

          sOldKey = m_colSortRowInfo.ItemVar(lNumImages)                                   ' get the old key
          lColumn = Piece(sOldKey, "^", 3, False)
          sTempIconStr = m_colImageInfo.Item(CStr(Index & "^" & lRow & "^" & lColumn))  '
          sNewKey = CStr(.Index & "^" & lCnt & "^" & lColumn)                           ' get the column, add to new key
          If (Len(sTempIconStr)) > 0 Then                                               ' if we have an image (didn't already remove it)
            Call m_colImageInfoSorted.Add(sTempIconStr, sNewKey)                        ' Add the new image location
          End If
          On Error GoTo 0
        Next lCnt
      End If
    Next lNumImages
  End With
End Sub

而且wahlah,只需要调用sub:

Call SortImageCollection(Index)

我知道SortImageCollection()子不是最有效的。如果有更好的方法来进行这种映射,请告诉我,我对响应很感兴趣,但这样做效果很好,并且从最终用户的角度来看并没有明显减慢,所以我很满意它。