I am able to get the visible rows in the grid, but how do I get the visible columns? I am only interested in the columns that are visible in the active scroll region, not anthing that is out of view.
You can get that list through the property called ActiveColScrollRegion. Here's a quick snippet showing it in action.
ColScrollRegion csr = this.ultraGrid1.ActiveColScrollRegion; foreach (VisibleHeader vh in csr.VisibleHeaders) { MessageBox.Show(vh.Header.Caption); }
I tried using your suggestion. The VisibleHeaders seem to be GroupHeaders. From that I have to get all the columns in the group and loop through them, checking the GetUIElement on each of them as I loop. This works, but it seems like there should be a more efficient way to get the visible columns. Am I missing something?
rehemann said: I tried using your suggestion. The VisibleHeaders seem to be GroupHeaders. From that I have to get all the columns in the group and loop through them, checking the GetUIElement on each of them as I loop. This works, but it seems like there should be a more efficient way to get the visible columns. Am I missing something?
Are you able to post a code snippet of how you've integrated my suggestion, along with the event or method you used?
When I added groups to my own test and ran the code I previously posted it didn't pull group headers, it pulled actual columns that were visible as before. To be extra through I'll put a screen capture below of what my test looked like.
Note: If the image appears cutoff above, just click on it. It'll navigate to the image in a new window.
I put in some debug code and all I ever get is Group Headers. I never get column headers. Here's The code I am using to get the visible columns. The formatting looks bad. You might have to paste it into a code window for readability.
grdGrid.ActiveColScrollRegion.VisibleHeaders
HeaderBase = objVisibleHeader.Header
Then
(objHeader, GroupHeader)
objGroupHeader.Group.Columns
UltraGridCell = e.Row.Cells(objUltraGridColumn.Key)
'make sure the cell is not hidden...
'make sure the cell is visible on the screen...
'this is definitely a grid cell that is visible on the screen...
If
Next
Testing out your code, I see it behaves exactly as you described. Although, I think you over complicated my previous snippet. Try replacing your section of code with the snippet below.
Dim csr As ColScrollRegion = Me.ultraGrid1.ActiveColScrollRegion For Each vh As VisibleHeader In csr.VisibleHeaders MessageBox.Show(vh.Header.Caption) Next
When you run the snippet in your application it should pop up a message box with the column name like the screen capture I posted. Inside the For..Next block you can place your code for the processing that needs done based on the visible columns.
Hi Torrey. I put a debug.print into my loop through the visible header objects and all I ever get is group headers, never column headers. See the screencap below:
Rich,
I talked with our Engineering department, and what you're doing is really the best way to go about doing it.
I don't doubt for a second that your code works, Torrey. I appreciate you looking at this issue. I know the grid is very complicated and I am using a ton of its features in my app.
Thanks
Rich
rehemann said: That's what I was trying to tell Torrey in my previous post. I have to drill down through the groups to get to the columns and then loop through all the columns in the group and check if they are visible. I have some grids with quite a few column in them and was looking for a quick and dirty way to get the visible columns. My code is doing what you suggest. I was just trying to find a more efficient way. Thanks!
That's what I was trying to tell Torrey in my previous post. I have to drill down through the groups to get to the columns and then loop through all the columns in the group and check if they are visible. I have some grids with quite a few column in them and was looking for a quick and dirty way to get the visible columns. My code is doing what you suggest. I was just trying to find a more efficient way.
Thanks!
More than likely there is some factor that causes group headers to be pulled when the grid is set up in a specific way with certain properties used. Either way I find it a little odd in functionality behavior, and can't get it reproduce as of yet to submit a bug.
If you're curious to see this from the perspective I was answering and replying with, take a look at this sample. I created a side by side method sample (using VB this time). Method 1 is using code I replied with first to get the visible headers, and method 2 is using Dave's latest code snippet. If you don't have VS2010 & 2010.3, take a peek into the bin folder for the compiled executable.
The drill down seems to be a bit safer since the grid is using coming up different functionality for similar methods. Sooner or later I'll figure out the specifics of this.
Hello Rehemann,
The VisibleHeaders property returns the topmost level of headers. So, if you have the columns in groups, it will return the visible group headers. You can do something like the following to get the columns, but it will get some columns that might not be visible. I'm assuming that's not what you want, but I might be wrong.
VisibleHeadersCollection vhc = ultraGrid1.ActiveColScrollRegion.VisibleHeaders; foreach (VisibleHeader vh in vhc) { if (vh.Header is GroupHeader) { GroupHeader gh = vh.Header as GroupHeader; foreach (UltraGridColumn ugc in gh.Group.Columns) { Debug.WriteLine(ugc.Header.Caption); } } }