有没有办法将数据与不显示给用户的 MSFlexGrid 单元格相关联?
Is there a way to associate data with an MSFlexGrid cell that is not displayed to the user?
假设我有你的标准 MSFlexGrid。我在一个已经有工具提示的单元格中有一个图像。
我想要做的是在与单元格关联但不向最终用户显示的单元格中存储关于图像的字符串。
我一直在查看 MSDN 网站上的属性,但我没有看到任何有用的东西。
这可能吗?有没有人做过类似的事情?我不反对使用不一定是为数据存储而设计的属性,前提是它们还没有被使用,但显然这是不可取的。
这就是我为那些可能想要做同样事情的人所做的。它不优雅,不漂亮,但它有效。
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
现在在 do display 中,我们从模型中获取数据,并通过第一次 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 作为集合的 "item" 并且键是网格 Index^m_TrackerRow^Column。
对于m_colSortRowInfo我设置相同的值(Index^m_TrackerRow^Column)作为项目然后键只是一个简单的迭代索引。
现在我遇到的问题是这些图像存在于网格中,但除了单元格包含或不包含图像/文本之外我对它们一无所知。由于与此 post 无关的原因,我需要将图标键与图像相关联。
现在,我们已经获得了图像所在模型的网格、行和列,但我们不知道它实际位于网格中的什么位置。列保持不变,但根据用户对网格的排序方式,行可以更改。这是关键的挑战。
我们有办法将模型网格行映射到特定的 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
哇哇,只需调用子程序即可:
Call SortImageCollection(Index)
我知道 SortImageCollection() 子不是最有效的。如果有更好的方法来执行此映射,请告诉我,我对响应很感兴趣,但这运行良好,并且从最终用户的角度来看没有明显的减速,所以我对此很满意。
假设我有你的标准 MSFlexGrid。我在一个已经有工具提示的单元格中有一个图像。
我想要做的是在与单元格关联但不向最终用户显示的单元格中存储关于图像的字符串。
我一直在查看 MSDN 网站上的属性,但我没有看到任何有用的东西。
这可能吗?有没有人做过类似的事情?我不反对使用不一定是为数据存储而设计的属性,前提是它们还没有被使用,但显然这是不可取的。
这就是我为那些可能想要做同样事情的人所做的。它不优雅,不漂亮,但它有效。
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
现在在 do display 中,我们从模型中获取数据,并通过第一次 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 作为集合的 "item" 并且键是网格 Index^m_TrackerRow^Column。
对于m_colSortRowInfo我设置相同的值(Index^m_TrackerRow^Column)作为项目然后键只是一个简单的迭代索引。
现在我遇到的问题是这些图像存在于网格中,但除了单元格包含或不包含图像/文本之外我对它们一无所知。由于与此 post 无关的原因,我需要将图标键与图像相关联。
现在,我们已经获得了图像所在模型的网格、行和列,但我们不知道它实际位于网格中的什么位置。列保持不变,但根据用户对网格的排序方式,行可以更改。这是关键的挑战。
我们有办法将模型网格行映射到特定的 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
哇哇,只需调用子程序即可:
Call SortImageCollection(Index)
我知道 SortImageCollection() 子不是最有效的。如果有更好的方法来执行此映射,请告诉我,我对响应很感兴趣,但这运行良好,并且从最终用户的角度来看没有明显的减速,所以我对此很满意。