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?
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); } } }
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!
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!
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.
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
Rich,
I talked with our Engineering department, and what you're doing is really the best way to go about doing it.