Hi,
I am having a different kind of requirement.
I have two lines of text in a single cell in Ultrawingrid.
I have to apply font size of 14 and color black to first line text.
And font size of 12 and color blue to second line text.
Could you please let me know how to do it?
Thanks,
Venkat.
Hi Venkat,
You could set the Style of the column to FormattedText. And then use XML as the Value of the cell to control the formatting. The custom XML format used by a FormattedText cell in the grid is the same one used by the UltraFormattedLinkLabel or UltraFormattedTextEditor controls.
i have used e.Row.Cells[i].CellDisplayStyle = CellDisplayStyle.FullEditorDisplay into ultraGrid_InitializeRow event. Then how i can use two different font sizes for the text of the same cell?
pls let me know if any options avail.
Mosam
Hi ,
One more observation - i would like to share with you.
In my original sample applicaiton - if you observe adding image to cell and button is written inside ultraGrid_InitializeRow() event where i am looping through row band columns one by one and will decide to add image and button based upon specific column/cell value. As per your sample POC - adding image and button logic is within setter of Value of CellInfoControl.cs so, can you pls let me know how i can shift that logic inside ultraGrid_InitializeRow() or any other way to do so.
Hi Mosam,
I'm still confused. Why are you using AutoSizeHeightOnly? That means that the label will only resize it's height and never it's width. Also, this property is obsolete and the same effect can be acheived another way as mentioned by the warning you can see in the application.
So are you thinking that you want the width of the column to be fixed and only the height of the rows will AutoSize to the contents? That's the only way that would make sense. But that's also going to make the preferred width of the UserControl ambiguous. So I'm having a a hard time wrapping my head around how that would work. I guess you could base the width on the OTHER labels and buttons and ignore width as far as the second label is concerned. But you have both labels set to AutoSizeHeightOnly, so that seems contradictory. That means there is no way to estabslihed the preferred Width. It's not clear to me what you want here. It sounds like what you want might not even be possible because there is a contradiction there. I recommend that you override GetPreferredSize on your UserControl and maybe play around with it and see how is works. Regarding the Image and/or buttons in the cells, you can't do that in InitializeRow when using UltraControlContainerEditor. The UltraControlContainerEditor essentially replaces the entire cell with a control. The grid will apply some Appearence property to your control like BackColor and ForeColor, because those are properties on Control. But it can't possible apply the Appearance.Image, and UltraControlContainerEditor doesn't suppose EditorButtons. If you want to change the button(s) that exist in the UserControl, then you would have to do that in the Value property setter and base that decision on something in the cell's value, just like I am doing with the Arrows image now. And the same applies to any other images.
Hi Team,
1) If you observe grid column width has been set to 200 if cell text goes beyond some length in sample application which I have sent you. So, it should auto size height in the scenarios where text goes beyond cell display limit. I have used AutoSizeHeightOnly property in sample application to do so. Ultralabel1 can have long texts within but ultralabel2 can have max 60-70 chars limit as per our requirement. So, in this scenario label1 should display full texts and should increase its height accordingly. I have tried to use GetPreferredSize on usercontrol but still its not showing label1 text values fully into cell. attaching sample poc here.
Can you pls update sample app for the same and send me. I have already provided long text example in my previous reply. e.g. "888 aaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbb ccccccccccc eddddddddddddd 123457888\n(140011-24558667 %)". Here texts before \n should be added into first label and text after \n should be added into second label. Ultra grid cell should display such values properly.
I hope, now it's pretty clear.
2) For second issue regarding image and button should be visible into cell - As per our requirement, based upon specific value in cell - it should add image and button into cell so, currently we are checking different column values for the same in Grid_inititalrow() event. In your sample - its added into setter of value property. Is there any other way to hide controls and then unhide them on initializerow() event or can we access other column values at setter of value property?
We are evaluating this usercontrol approach based upon our requirement to display full texts, image and button on same cell of ultragrid.
If it doesn’t work then other alternative for us to go to xml approach using UltraFormattedTextEditor for which I have attached sample in my previous replies. Into that approach - can we show image on top right corner of the cell instead immediately after first text of the cell?
Also, if too long text come up then can we resize cell of ultragrid to show full texts within?
Based upon solutions to be provided for above issues, we would decide on which approach to go further for implementation.
Can you please help us here soon as we need to apply solutions quickly to our application.
4643.SampleUltraGrid (2).zip
1) Okay... a few things here.
Your sample is trying to set the Size of the UserControl inside of the Value settings, You should not do that.
Also, It's not a good idea to set the column width inside of InitializeRow because you are continuously setting and re-setting the same value, which makes no sense. So I moved that code into InitializeLayout. I also set the MaxWidth and MinWidth on the column, because the only way this will work where only the height adjusts is if the column has a fixed width that never changes. And the grid has no way to notify the UserControl of this, so I hard-coded the PreferredSize of the UserControl to the same value (200) inside of GetPreferredSize. So then all you really need to do is return the ideal height of the UserControl, which is a simple matter of adding up the height of UltraLabel1 and UltraLabel2 and adding in some padding.
public override System.Drawing.Size GetPreferredSize(System.Drawing.Size proposedSize) { var idealHeight = this.ultraLabel1.Top + this.ultraLabel1.Height; idealHeight += 8; // padding idealHeight += this.ultraLabel2.PreferredSize.Height; idealHeight += 8; // padding return new Size(200, idealHeight); }
2475.SampleUltraGrid.zip
2)
mosam patel said: Is there any other way to hide controls and then unhide them on initializerow() event or can we access other column values at setter of value property?
No. As I said, the only thing the ControlContainerEditor has to work with is the Value property of the cell. So some part of the cell's value would have to return some kind of information that determines whether to display the image/button.
If the visibility of the image and/or button cannot be determined from the cell's value, then what you could do is hide the actual column in the grid and then replace it with an unbound column and then use the InitializeRow event to populate that unbound column with the data it needs - either in a parsable string or even as some kind of object with properties for each piece of data That way the original value in the hidden cell is not affected.
Hi Mike,
Even after using below, it seems its still cut some texts in cell for label1 in your attached sample.
public override System.Drawing.Size GetPreferredSize(System.Drawing.Size proposedSize) { var idealHeight = this.ultraLabel1.Top + this.ultraLabel1.Height; idealHeight += 8; // padding idealHeight += this.ultraLabel2.PreferredSize.Height; idealHeight += 8; // padding return new Size(200, idealHeight);
}
below is screenshot for it.
text value is : 888 aaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbb ccccccccccc eddddddddddddd 123457888\n(140011-24558667 %)"
Can you pls provide your input
mosam patel said:Thanks for looking into it. Can you pls provide example as you mentioned for using the SetBoundsCore and GetPreferredSize. Also, if you can update sample poc - it would save several back and fro as resolving one issue actually starts seeing another issue within sample poc which we have seen so far.
I have provided you with several iterations of the sample that handle both of these methods and arrange the controls or return an ideal size. So you have all the pieces you need to determine how you want the controls within the UserControl to be arranged and what the ideal size of the UserControl should be. You will need to take it from there and determine what you requirements are.
mosam patel said:I have asked you query for alternative xml approach using UltraFormattedTextEditor for which I have attached sample in my previous replies. Into that approach - can we show image on top right corner of the cell instead immediately after first text of the cell? Also, if too long text come up then can we resize cell of ultragrid to show full texts within instead currently it displays scroll bars on cell if long text values come. Can you pls provide your suggestion on this ?
The img tag allows you to place an image in-line with the text or also floating separately. That tag (and all of the supported Xml tags) are documented here. So you could try using a floating image.
Hi Mike,Thanks for looking into it. Can you pls provide example as you mentioned for using the SetBoundsCore and GetPreferredSize. Also, if you can update sample poc - it would save several back and fro as resolving one issue actually starts seeing another issue within sample poc which we have seen so far.
As per my last reply- i have mentioned one another issue as well that is on click on cell, label2 starts displaying overlapping with label1 texts and label1 text displays not fully on top of label2 - can you pls provide your input for this ?
I have asked you query for alternative xml approach using UltraFormattedTextEditor for which I have attached sample in my previous replies. Into that approach - can we show image on top right corner of the cell instead immediately after first text of the cell? Also, if too long text come up then can we resize cell of ultragrid to show full texts within instead currently it displays scroll bars on cell if long text values come. Can you pls provide your suggestion on this ?
So I guess I was mixed up about which text you were putting into each label. But at this point, this is really going way beyond what I can do for you in terms of support. You need to figure out what you want this control to look like in the cell and arrange the controls sing the SetBoundsCore and GetPreferredSize. I can only provide you with an example, I can't write a working control for you. What you are seeing here, I think, is that you have the UltraLabel1 set to AutoSizeHeightOnly and you are setting it to a very long string, so it's increasing it's own height and covering up UltraLabel2. The solution to that problem is to change the code in SetBoundsCore which is arranging the controls inside the UserControl and place them in such a way that that doesn't happen. When I wrote that code, I was assuming that UltraLabel1 was always going to be one line, but that is apparently not the case. So you can force UltraLabel1 to refresh it's PreferredSize by setting AutoSize to false and back to true, get the PreferredSize and the position UltraLabel2 such that it is underneath UltraLabel1. And then you will probably need to do the same thing to get the correct PreferredSize of UltraLabel1 inside of GetPreferredSize, because my sample code currently is not doing that because, as I said, I was assuming UltraLabel1 is always a single line.
After applying above GetPreferredSize, It starts displaying label1 text but yet not displaying label2 texts in cell. see in below screenshot.
we require to display label1 full texts and then label2 full text in new line.
Also, when i click on column3 highlighted cell then it displays as below. Here, label2 starts displaying overlapping with label1 texts and label1 text displays not fully on top of label2.
Can you pls give your input and update sample application for above issues.
Nope. I am wrong. The first line is wrapping in the middle of a word, so that can't be right. So I think the issue is that PreferredSize on the UltraLabel2 is stale, so we just need to give the label a kick.
It seems to work better if I force it to resize before getting the PreferredSize...
public override System.Drawing.Size GetPreferredSize(System.Drawing.Size proposedSize) { var idealHeight = this.ultraLabel1.Top + this.ultraLabel1.Height; idealHeight += 8; // padding this.ultraLabel2.AutoSize = false; this.ultraLabel2.AutoSize = true; idealHeight += this.ultraLabel2.PreferredSize.Height; idealHeight += 8; // padding return new Size(200, idealHeight);
}The height is now too big, but that's likely because I just used 8 for padding and that's not the correct value.