1

我们使用 Infragistics UltraWinGrid 作为自定义控件的基类。将使用此控件显示搜索结果的项目之一需要在未找到匹配项时显示用户友好的消息。

我们希望将该功能封装到派生控件中——因此使用控件的程序员除了设置要显示的消息之外不需要进行任何自定义。这必须以通用方式完成 - 一种尺寸适合所有数据集。

UltraWinGrid 中是否已经允许这种类型的使用?如果是这样,我会在哪里找到它隐藏。:-)

如果需要对该功能进行编码,我可以考虑一种算法,该算法将向设置的任何记录集添加一条空白记录并将其放入网格中。在您看来,这是处理解决方案的最佳方式吗?

4

1 回答 1

2

我不知道这是否会有所帮助,但这是完成线程。我没有找到内置的方法,所以我解决了这个问题如下:在我继承 UltraGrid 的类中

Public Class MyGridPlain
Inherits Infragistics.Win.UltraWinGrid.UltraGrid

我添加了两个属性,一个用于指定开发人员在空数据情况下想要说什么,另一个用于使开发人员能够将他们的消息放置在他们想要的位置

Private mEmptyDataText As String = String.Empty
Private mEmptyDataTextLocation As Point = New Point(30, 30)Public Shadows Property EmptyDataTextLocation() As Point
Get
     Return mEmptyDataTextLocation
End Get
Set(ByVal value As Point)
    mEmptyDataTextLocation = value
    setEmptyMessageIfRequired()
End Set
End Property

Public Shadows Property EmptyDataText() As String
Get
   Return mEmptyDataText
End Get
Set(ByVal value As String)
  mEmptyDataText = value
  setEmptyMessageIfRequired()
End Set
End Property

我添加了一个方法来检查空数据并设置消息。另一种方法将删除现有的空消息。

    Private Sub setEmptyMessageIfRequired()

        removeExistingEmptyData()

        'if there are no rows, and if there is an EmptyDataText message, display it now.
        If EmptyDataText.Length > 0 AndAlso Rows.Count = 0 Then
            Dim lbl As Label = New Label(EmptyDataText)
            lbl.Name = "EmptyDataLabel"
            lbl.Size = New Size(Width, 25)
            lbl.Location = EmptyDataTextLocation
            ControlUIElement.Control.Controls.Add(lbl)
        End If
    End SubPrivate Sub removeExistingEmptyData()
       'any previous empty data messages?
       Dim lblempty() As Control = Controls.Find("EmptyDataLabel", True)
       If lblempty.Length > 0 Then
           Controls.Remove(lblempty(0))
       End If

   End Sub

最后 - 我在网格的 InitializeLayout 事件中添加了对空数据的检查。

Private Sub grid_InitializeLayout(ByVal sender As Object, _
      ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) _
      Handles MyBase.InitializeLayout    

     setEmptyMessageIfRequired()

End Sub
于 2009-08-13T19:10:51.500 回答