I have an UltraListView control, in which I display two columns (or subitems) which contain an UltraProgressBar. For the most part, it works fine, but I want to extend the functionality a bit, in two ways:
1) I want to change the colour (or background image), so it is obvious which is which at a glance. I'm using an app style, and changing the appearance has proven to be problematic. I can make the bar (in the progress bar) disappear, by using:progBar.FillAppearance.ImageBackgroundAlpha = Alpha.Transparent;but for the life of me I cant get a different color or image to appear there. Would I need to use a draw filter for this?
2) I also want to customise the text in the progress bar, so rather than saying something like "20%", it says "20% (5/25)". As the whole listview column shares the one progress bar control, applying the text to the progress bar changes the whole column.
If anyone could suggest an answer to either of my queries, I would be much appreciated.
Hi,
There are a lot of different factors at work here, so it's hard to answer your questions without a more concrete example to work with.
Can you post a small sample project demonstrating what you are doing and using the same isl you are using?
It might not be possible to do this while there is an isl applied. The isl will apply to all controls, so it may be overriding any settings on the UltraProgressBar control. Sometimes you can override the isl settings by applying an Appearance to an individual sub-object like a grid cell. But since you are working with an entire column and an editor here, I don't know if it can be done.
As for setting the text, this should be a simple matter of setting the Text property on the UltraProgressBar control you are using. There are replacement codes for the percentage as well as the current value, maximum value, etc.
Mike,
I have attached a sample app, which demonstrates both issues i have raised. There is a bit of text in the <summary> of Form1 which should give you a pointer to what I'm trying. The appstyle is there, although you may need to copy it to the bin directory.
I have tried that with the ultraprogressbar, but it seems with the UltraListView control, you cant assign a progress bar per row/item - you can only assign one for the whole column. Hence, they all end up with the same text.
Thanks
Shanon.
Hi Shanon,
As I suspected, I don't see any way to make the two ProgressBars have two different Appearances. The problem is that the Application Style library is applying to the ListView and so it applies to all of the controls within the ListView.
If you had two independent UltraProgressBar controls on the form, you could do it by turning off ApplicaitonStyling for one of them, or by assigning a different StyleSetName to one or both. But since they are both used by the same control, I cannot see any way to do it, short of using a DrawFilter.
As for the text, I'm afraid I don't see the problem. You said you just wanted to change the format to something like "20% (5/25)".
Now you seem to be saying that you want a different format on each row. You are correct that you cannot do that, but you didn't mention anything about that in your original post, so I think one of us is confused. :)
I tried this and it worked fine for me:
progBar.Text = "[Formatted] ([Value]/[Maximum])";
Thanks for your reply.
I'm happy to use a DrawFilter. This is one of the things I have played around before posting my questions here. I couldnt get it to work though. I'm guessing at the moment that the DrawFilter would need to be pladed on the ultralistview, not the progress bar itself. This is as far as I got before realising it didnt seem to be doing anything close to what I wanted:
---- CODE START -----
public Infragistics.Win.DrawPhase GetPhasesToFilter(ref Infragistics.Win.UIElementDrawParams drawParams) { if ((drawParams.Element is ImageUIElement) && (drawParams.Element.GetContext(typeof(UltraListViewSubItem)) != null)) { return DrawPhase.BeforeDrawImageBackground; } return DrawPhase.None; } public bool DrawElement(Infragistics.Win.DrawPhase drawPhase, ref Infragistics.Win.UIElementDrawParams drawParams) { UltraListViewSubItem subItem; switch (drawPhase) { case DrawPhase.BeforeDrawImageBackground: subItem = (UltraListViewSubItem)drawParams.Element.SelectableItem; Console.WriteLine(subItem.Key); break; } return false; }
---- CODE END -----
Sorry if I wasnt clear about what I was trying to acheive originally - thats why I made the sample app as close to my real one as possible. Yes, the text should say "X% (Y/Z)", where X, Y and Z may be different for each line (but X will represent Y/Z). I was starting to lean towards a DrawFilter for this one too.
While I have gotten DrawFilters working in the past, this was with an UltraGrid, where there are examples available that were 80% of what I wanted. I couldnt find any examples using the UltraListView or Progress bar.
After quite a bit more work, I am a little closer, but still not quite there. I have made a DrawFilter that can replace the graphic of the UltraProgressBar. It looks as follows:
public Infragistics.Win.DrawPhase GetPhasesToFilter(ref Infragistics.Win.UIElementDrawParams drawParams)
{
if (drawParams.Element.GetType() == typeof(ProgressBarFillUIElement))
return DrawPhase.BeforeDrawImageBackground; return DrawPhase.None; }
public bool DrawElement(Infragistics.Win.DrawPhase drawPhase, ref Infragistics.Win.UIElementDrawParams drawParams)
switch (drawPhase)
case DrawPhase.BeforeDrawImageBackground:
drawParams.AppearanceData.ImageBackground = Resources.ControlImages.GridBackgroundEditableNotSelected;
break;
} return false; }
The problem with this, is that I have no way of knowing which progress bar it is. All I have access to in the drawphase is the ProgressBarFillUIElement, which I cant get the actual control data out of.
I worked it out. I was populating the ProgressFillTextUIElement.Text property. This only shows over the progress bar graphic/bar. So it shows up fine for high percentages (like 80-100%), as the whole text is in front of the bar graphic. But for lower pecentages (0-20%), the text is to long to fit over the bar graphic, so not all of it will show.
I managed to get around this by also updating the TextUIElement.Text property.
Although my understanding of all the UIElements is sketchy at best, I think I'm now updating the text element that is on top of the progress bar graphic (ProgressFillTextUIElement), and the text element that is behing the progress bar graphic (TextUIElement)
Again, thanks for your help.
I cant use the replacement codes becuase the whole column of the UltraListView uses a single common UltraProgressBar.
The format I want is "X% (Y/Z)". Z will be different for each row, which to my knowledge will make it impossible, as there is no way of setting a different maxvalue for each row in the listview.
I'll put an updated sample app soon.
Thanks for your help.
Why are you changing the text in the DrawFilter instead of just using the replacement codes?
I can't see any reason why 0 should be any different from any other value if you are setting the Text property directly on the UIElement. Unless the control uses different elements for 0, which seems unlikely.
If you want to post a small sample demonstrating this, I'd be happy to take a look, but I still think you are going about this the hard way. :)
Thanks. I have my way working (checking every point), but I might give your way a go too.
I am having problems changing the text to "X% (Y/Z)" though. If the percentage figure is non-zero, it works fine. But if the percentage figure is zero, it ignores the text I put in it, and just puts "0%".
In GetPhasesToFilter I'm using:
if (drawParams.Element.GetType() == typeof(ProgressFillTextUIElement)) return DrawPhase.BeforeDrawForeground;
And in DrawElement I am doing something like:
case DrawPhase.BeforeDrawForeground:
ProgressFillTextUIElement progressFilleTextUIElement = drawParams.Element as ProgressFillTextUIElement;
progressFilleTextUIElement.Text = "my text here"
(obviously leaving out some detail there).
Any idea why it would not work for zero? I can provide a full working sample if it maks your life easier.
fweeee said:I am guessing I can get around this by checking more points if it doesnt find a match (top right, middle, etc). I'll see how I go with this.
Hm, you are right, I didn't think of that.
What I would do is get the Rect of the control element, and then do an intersection.
case DrawPhase.BeforeDrawImageBackground: ProgressBarFillUIElement progressBarFillUIElement = drawParams.Element as ProgressBarFillUIElement; if (progressBarFillUIElement == null) return false; ControlUIElementBase controlUIElementBase = progressBarFillUIElement.GetAncestor(typeof(ControlUIElementBase)) as ControlUIElementBase; if (controlUIElementBase == null) return false; Rectangle rect = progressBarFillUIElement.Rect; rect.Intersect(controlUIElementBase.Rect); if (rect.IsEmpty) return false; UltraListViewSubItem subItem = this.listView.SubItemFromPoint(rect.Location); // Change the appearance here based on subItem.Column.Key break;