How can I make an editable row, header or something similar in an infragistics grid, above the columnheaders, to allow easy filtering in the grid

Posted on 2005-04-21
Last Modified: 2012-05-05
Hi, I'm currently making a set of standard controls for our frame work. One of these is a datagrid. I inherit from the infragistics ultrawingrid, because it holds most of the features we need. However, I have to implement 2 ways of filtering data in the grid. One is using the embedded filter options, using operators and the likes, but this is for advanced users. I need to make an editable cell above each column header where the user can type something in and then filter the data in the grid by limiting the values in the column to those like the value inserted by the user.
For example in a grid with clients, a user should be able to click on the filter cell above the column "Name" and type "A", then the grid should filter all rows, showing only those holding a name starting with 'A'.
I know how to set filters and all that, but I can't find a way to get a row above the columnheaders. I tried using a band, but that messes up my dataset and I don't like that very mucht. Besides it also keeps a distance between the band below. and I have to add a band  for each band I already have, linking them and such.

Is there another (easier) way? I tried the forums of infragistics already but they don't have an anwer (say it can't be done, yet I found a way using bands, so...) which is why I'm turning to you experts.
Question by:Paybit
    LVL 2

    Accepted Solution

    You could try to use groupheaders abve each column and then using a textbox to simulate editability.

    Here's an example on how to add group headers and make them look like textboxes:

    Private Function Addgroupheader(thing) As Boolean
        Dim band As UltraGridBand
        'Loop through all the bands
        For Each band In Me.DisplayLayout.Bands
          With band
            Dim c As UltraGridColumn
            Dim g As New UltraGridGroup
            'make a group for each column, holding only that column
            For Each c In .Columns
              'don't add a group for hidden columns as it is not necessary
              If c.Hidden = False Then
                .Groups.Add("filter " & c.Key & " " & band.Index, "")
                g = .Groups("filter " & c.Key & " " & band.Index)
                .LevelCount = 1
                'the groupkey is the columnname + the bandindex
                .Columns(c.Key).Group = .Groupsc.Key & " " & band.Index)
                c.Group = g
                'make it look like an editable cell
                g.Header.Appearance.BackColor = Color.White
                g.Header.Appearance.TextHAlign = HAlign.Left
                'as fixed columns are overruled by groups, set the groups fixed if the column is fixed
                g.Header.Fixed = c.header.fixed
               End If
          End With
      End Function

    Author Comment

    Ok, I have the headers and they look just like  textboxes, but I can't click on them and put text in. How do I do that?
    LVL 2

    Expert Comment

    Make a class variable t as textbox:
    private t as textbox

    In the click event on the grid check the clicked element and place the textbox.
    Private Sub DataGrid_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
    dim myElement as uielement
    'Get the element clicked on
    myElement = Me.DisplayLayout.UIElement.ElementFromPoint(New Point(e.X, e.Y))
    'if it is a header, set the textbox
        If Not myElement.GetContext(GetType(GroupHeader)) Is Nothing Then
          Dim g As GroupHeader = CType(myElement.GetContext(GetType(GroupHeader)), GroupHeader)
          Dim r As Rectangle = myElement.RectInsideBorders
          'Dim f As String = InputBox("Filter op:", g.Group.Key, "")
          'g.Caption = f
          g.Appearance.BackColor = Color.White
          'Me.PerformAction(UltraGridAction.EnterEditMode, False, True)
          blnHandled = True
          If t Is Nothing Then
            t = New TextBox
          End If
          t.Visible = False
          t.CausesValidation = False
          t.Left = r.Left
          t.Width = r.Width
          t.BorderStyle = BorderStyle.None
          t.ForeColor = g.Appearance.ForeColor
          t.Font = Me.Font
          t.Text = g.Caption
          t.Tag = g.Group
          g.Group.Tag = t
          blnHandled = False
          t.Visible = True
          'Because the height of a textbox is set when it becomes visible and is fixed, based on the font size
          'We adjust the top of the textbox to make it appear centered within the header.
          Dim hDif As Integer = CType(Math.Round((r.Height - t.Height) / 2, 0), Integer)
          t.Top = r.Top + hDif
        End If
      End Sub

    Next add code to the paint event to keep the textbox positioned where you want it in case you resize the grid.

    Private Sub DataGrid_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        If Not t Is Nothing Then
          Dim r As Rectangle = CType(t.Tag, UltraGridGroup).Header.GetUIElement.RectInsideBorders
          t.Left = r.Left
          t.Left = r.Left
          t.Width = r.Width
          t.Height = r.Height
          'Because the height of a textbox is set when it becomes visible and is fixed, based on the font size
          'We adjust the top of the textbox to make it appear centered within the header.
          Dim hDif As Integer = CType(Math.Round((r.Height - t.Height) / 2, 0), Integer)
          t.Top = r.Top + hDif
        End If
      End Sub

    If you allow groups and columns to be swapped and/or moved, you need to add code to the AfterGroupPosChanged and AfterColPosChanged events to make sure the groups and columns swap/move together. The easiest way is to pick up the column the group is linked to, move the groups visibleposition to the columns VisiblePositionWitinBand and to remove and then re-add the column to the group.

    Author Comment

    Got it working... and the guys over at Infragistics said it couldn't be done...Thanks a lot.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now