Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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
4
Medium Priority
?
1,449 Views
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.
0
Comment
Question by:Paybit
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
Fenris_Lokisson earned 2000 total points
ID: 13864477
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
        Next
      End With
    Next
  End Function
0
 

Author Comment

by:Paybit
ID: 13873661
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?
0
 
LVL 2

Expert Comment

by:Fenris_Lokisson
ID: 13883181
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
        Me.Controls.Add(t)
      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.SelectAll()
      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
      t.Focus()
    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.
0
 

Author Comment

by:Paybit
ID: 13884295
Got it working... and the guys over at Infragistics said it couldn't be done...Thanks a lot.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month11 days, 17 hours left to enroll

564 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