I have a Windows Form application with a basic grid of data. I have enabled row filtering via the header icon.
My user has asked if I can add a button to the top of each column which allows them to copy the contents of the cell in the first row of that column to all the other cells in that column, and I'm trying to figure out the best way to accomplish this.
Can I add a custom button to a column header and create an event handler for it?
Or can I override the event hanlder for one of the other existing column header buttons?
Or can I freeze the first row so that it is unaffected by scrolling/filtering and add buttons to the cells in this row?
I guess the real question is "What is the best way to accomplish what I'm trying to do?"
Thanks so much!
Steve
Hi Steve,
Almost any of these would work. The cleanest solution would be the first one.
sweeks said:Can I add a custom button to a column header and create an event handler for it?
To do this, you would use a CreationFilter. CreationFilter's have a bit of a learning curve and they can be a bit daunting if you haven't used them before, but they are incredibly powerful tools and learning them is worth your while.
Using a CreationFilter, you could add a ButtonUIElement into the HeaderUIElement and adjust the other UIElements within the header to make room for it.
If you want to explore CreationFilters, I recomend that you search the Infragistics Knowledge Base for CreationFilter and you will find lots of sample - some of which may be pretty similar to what you want to do. Also, I strongly recommend that you get the Infragistics UIElementViewer Utility. It's very useful when dealing with UIElements.
If you don't want to go that route, then the next best thing would be:
sweeks said:Or can I freeze the first row so that it is unaffected by scrolling/filtering and add buttons to the cells in this row?
You can fix a row in the grid by simply setting the Fixed property on the row. You could loop through the cells in the row and set the Style on each cell to Button.
Also, the row will still be filtered out as normal. So you would need to handle the FilterRow event of the grid and prevent this row from being filtered.
Thanks Mike. I've been studying the Creation Filter and I think I have a VERY high level understanding of it as follows:
1. I create a Creation Filter2. I create a custom UI Element based on an existing one (image and button)3. I attach the creation filter to an Element on my form (ultrawingrid)4. In the Creation Filter, I add logic that will place the custom UI Element (button) in the element on my form(grid column header)
I apologize for bugging you, but I'm excited to get this working, and had a few more questions. I couldn't find any examples in the knowledge base that were specific to adding somthing to a column header.
Questions:
1. Do a attach the CreationFilter to the grid (i.e. mygrid.CreationFilter = myCreationFilter), or do I somehow attach it directly to column headers? My assumption is that I attach it to the grid, and that the Creation Filter logic will discern whether or not the UIElement is a column header and either add the button or not.
2. If my assumption is correct, what is the element the Creation Filter should be looking for which represents a coumn header? In debug mode, I've watched many elements come across but none of them appeared to be a column header. I've been able to add my button to various random places on the grid, but not in the column headers yet.
Thanks so much Mike!