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.
That's probably just the behavior of the UltraLabel where it only breaks on a space or other word-break. SInce you are forcing the width to 200 and you have a single word that will not fit that width, there's nothing it can do. So what do you want to happen in this case? You can't have it both ways - autosizing both width and height. One or the other has to be fixed in order to AutoSize the other.
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
BTW, I did some more testing and I find that when I use InitializeRow and apply an Appearance.Image to the cell, the image DOES display next to the UserControl. So the Appearance.Image is honored. I can't find any good way to place the image inside the UserControl without it also appearing outside the UserControl, though. So if you can live with the image displaying outside the UserControl on the left or right, that might be a good solution for you. All I did was this, inside InitializeRow: if (e.Row.Index %2 == 0) { e.Row.Cells[i].Appearance.Image = ImageServer.GetImage("Task"); }
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 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