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

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.
Who is Participating?
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
PaybitAuthor Commented:
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?
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.
PaybitAuthor Commented:
Got it working... and the guys over at Infragistics said it couldn't be done...Thanks a lot.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.