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
If the cell is showing the Xml instead of the formatting, then that almost-certainly indicates that the Xml is somehow invalid. What I would do is put an UltraFormattedTextEditor control on your form (or another form in another project) and then go to the Value property in the property grid and click the ellipsis. This will bring up the FormattedText editor dialog. You can paste the value of this particular cell into that window and it will display any error messages that occur when parting the Xml, so that might help you narrow it down. And you can edit the Xml in place to try to fix it.
I validated xml and it seems valid xml. still its showing the same as above given screen shot in previous reply. Any further suggestion? The same kind of text is showing properly on other cells of the ultra grid. it seems if its first cell or first time such data comes in cell then only such issue happens.
Thanks.
Did you try pulling out the Value property of the cell and copying that into an UltraFormattedTextEditor? If that works and shows the image correctly, then the only other explanation is that the grid cell is not set up to use FormattedText. If you can post a small sample project here that I can run and Debug, I'd be happy to take a look at it for you. :)
Hi Mike,
Attaching sample application. Can you please help me out in below issues.
1. Is there any way if I want to show red arrow image on top right corner exactly before H button is getting displayed currently? Below red arrow image should be displayed exactly before H button.
2. Here, I used xml approach to display formatted text, image and button in same cell of ultra win grid. Can you please provide other alternative in which I don't need to convert cell values into xml for displaying formatted text, image and button in same cell.
I appreciate all your help so far.
SampleUltraGrid.zip
Okay, I whipped up a sample to get you started with the ControlConainerEditor approach. It does make the code a lot simpler and cleaner, but it is by no means complete.
So the basic idea here is that I created a UserControl with 2 labels, a picturebox (for the arrows), and a button.
I hooked this up to the grid columns using ControlContainerEditor. When a grid cell paints, it sets the Value on the UserControl (which is called CellInfoControl) and the Value property on the control parses the string into the two labels.
Your original sample was using the cell index to determine whether or not to show the arrows, but you really can't do that here, and I'm sure you don't want to. That determination has to come from something in the value of the cell, so I used the top value here and parsed it into an int and then used odd or even, just to show give you an idea of what needs to be done.
It's worth nothing that since I specified only a RenderingControl on ControlContainerEditor, the cell will not allow editing, which means the user can't actually push the button. But that wasn't working in the sample as it already was, so I'm not sure if you need that or not. If you do need that, you will have to specify another instance of the UserControl as the EditingControl: this.controlContainerEditor.EditingControl = new CellInfoControl(); this.controlContainerEditor.EditingControlPropertyName = "Value"; this.controlContainerEditor.EnterEditModeMouseBehavior = EnterEditModeMouseBehavior.EnterEditModeAndClick;
And then handle the button click event on the UserControl using the grid's ActiveCell. Also, you might need to implement the Getter on the UserControl's Value property and re-build the string from the labels and such, reversing the parsing that is done in the Setter.
You might want to adjust the appearances and layout of the various controls inside the UserControl, and also maybe override GetPreferredSize so that auto-sizing works in the grid. But this should be enough to get you started.
8446.SampleUltraGrid.zip
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 ?
Hi Mosam,
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.