views:

456

answers:

1

We're using Infragistics UltraWinGrid as a base class for customized controls. One of the projects that will use this control to display search results has a requirement to display a user friendly message when no matches are located.

We'd like to encapsulate that functionality into the derived control - so no customization beyond setting the message to display is required by the programmer who uses the control. This would have to be done in generic fashion - one size fits all datasets.

Is there allowance in the UltraWinGrid for this type of usage already? If so, where would I find it hidden. :-)

If this functionality needs to be coded, I can think of an algorithm which would add a blank record to whatever recordset was set and place that into the grid. In your opinion, is this the best way to handle the solution?

And Thanks! for your time.

+1  A: 

I don't know if this will help, but here's to finishing up the thread. I didn't find a built in way, so I solved this problem as follows: In my class which inherits UltraGrid

Public Class MyGridPlain
Inherits Infragistics.Win.UltraWinGrid.UltraGrid

I added two properties, one to specify what the developer wants to say in the empty data case, and another to enable the developer to place their message where they want it

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

I added a method which will check for empty data and set the message if so. And another method which will remove the existing empty message.

    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

Last - I added a check for empty data to the grid's InitializeLayout event.

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

     setEmptyMessageIfRequired()

End Sub
BPerreault