Hi!
I want to add both text and a button to one of my ultragrid column header. I already disabled Sorting for that column, but I have no idea how to add a button. Even I found no information about handling header clicks.
Please help me!
Thanks,
Gergo
Hi Gergo,
There's no built-in functionality in the grid for adding a button to a column header, although we recently added the ability to put a CheckBox there.
If a checkbox is no good, then you would need to use a CreationFilter to add the button into the header in code. There's a discussion of this technique here:
Adding a button to a Column Header - Infragistics Community
Thanks for the answer.
Unfortunately the link you attached does not work.
I don't want to make it too complex; handling a click on the header could be enough for me. Could you tell me if i can handle if the user clicks on the ultra grid's header? So I could check which header cell was clicked and adjust business logic accordingly. However I could not find any events that could be used to handle header clicks.
Thanks in advance,
gergomeister said:Unfortunately the link you attached does not work.
Sorry about that. I don't know how that link got corrupted. I've fixed it now.
gergomeister said:I don't want to make it too complex; handling a click on the header could be enough for me. Could you tell me if i can handle if the user clicks on the ultra grid's header? So I could check which header cell was clicked and adjust business logic accordingly. However I could not find any events that could be used to handle header clicks.
Well, the first thing you'd want to do is turn off the default behavior of clicking on the header.So you could do something like this:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { e.Layout.Override.HeaderClickAction = HeaderClickAction.Select; e.Layout.Override.SelectTypeCol = SelectType.None; }
To trap a click on a header, you could do something like this:
private void ultraGrid1_MouseUp(object sender, MouseEventArgs e) { UltraGrid grid = (UltraGrid)sender; UIElement element = grid.DisplayLayout.UIElement.LastElementEntered; Infragistics.Win.UltraWinGrid.ColumnHeader header = element.GetContext(typeof(Infragistics.Win.UltraWinGrid.ColumnHeader)) as Infragistics.Win.UltraWinGrid.ColumnHeader; if (header != null) Debug.WriteLine(header.Column.Key); }
Hi
Thanks Mike
After i checked for element variable :
If grid.DisplayLayout.UIElement.LastElementEntered Is Nothing Then
it's worked fine.
thank you
Hi,
I'm not sure what you are asking.
The only object I can see I this code that could be causing a NullReferenceException is if the element variable is null. So you should probably check for that before you try to access a method on it.
Object reference not set to an instance of an object.
NullReferenceException occurs:
at System.Windows.Forms.Control.OnMouseUp(MouseEventArgs e) at Infragistics.Win.UltraControlBase.OnMouseUp(MouseEventArgs e) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m)
codes:
Dim grid As UltraGrid = DirectCast(sender, UltraGrid) ' Get the last UIElement entered by the mouse. Dim element As UIElement = grid.DisplayLayout.UIElement.LastElementEntered ' Try to get a column header. Dim columnHeader As Infragistics.Win.UltraWinGrid.ColumnHeader = TryCast(element.GetContext(GetType(Infragistics.Win.UltraWinGrid.ColumnHeader)), Infragistics.Win.UltraWinGrid.ColumnHeader)
the above statement is error
This works!
Thanks for your help!