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
I updated the sample with a couple of changes.
First, I enabled clicking the button.
Second, I noticed some weirdness with the positioning of the button and display of the arrows, so I fixed that in the user control. I also have to change the CellClickAction because you had it set to RowSelect and with that setting, the cell will never enter edit mode and so you will never be able to click the button. You might want to set CellClickAction on the columns that are not using the ControlContainer, but you can't really have both. Also, I hid a bunch of the columns that don't really work correct because the Value property isn't handling the case where the value of the cell doesn't have a line break in it. So you will need to update that to work in all cases. Regarding AutoSize, you will need to override GetPreferredSize on the UserControl and then figure out what the ideal size of the control will be. In this case, you can likely determine the width by adding the width of ultraLabel1 + ultraPictureBox1 + ultraButton1 and then presumably you will want to add some padding in there. And similarly, the height would be the height of ultraLabel1 and ultraLabel2 with some padding. But that's up to you. It's possible that the Width of those child controls is stale inside the GetPreferredSize method, so if you find that is the case, you might have to forced them to auto size by calling Update or Refresh, or do what I did in the SetBoundsCore and use PreferredSize instead of Size. Also, it looks like your grid is set to AutoFitStyle, so you can't resize the columns in this grid, anyway, so you will need to turn that off, if you want the user to be able to AutoSize.
4643.SampleUltraGrid.zip
Hi Mike,
I have tried to resize both labels using AutoSizeHeightOnly property and it gets auto resized as well. now it should resize cell also accordingly which is not happening. so, both label values are not getting displayed within grid cell.
Can you please update the attached sample for the same.
Thanks a lot for all your help.
8713.4643.SampleUltraGrid.zip
I'm not sure I'm following you. In my sample, I had AutoSize on both labels set to true. But the size of the labels will not have any bearing on the size of the UserControl. They are two completely different things. The UserControl needs to be resizable, so that it will fit inside the grid cell. The grid will size the control to the cellas it paints each cell. So the code I added which re-positions the buttons in SetBoundsCore is needed so that the control itself responds properly to resizing. AutoSizing related to when the user double-clicks on the right edge of the column header. In that case, the grid will ask the editor (in this case the UltraControlContainerEditor) for the preferred size based on the value of the cell. The grid also asks the editor for the size of preferred size if you are using other AutoSize settings like AllowColSize or RowSizing settings that include "Auto" for the initial size of the column or row. The UltraControlContainerEditor, of course, has no idea how to do that since the contents of the cell are determined by a bunch of arbitrary controls inside the UserControl. So it's up to you to make that calculation and implement GetPreferredSize on your UserControl.The sample you posted here seems to be working in that regard. The columns appear to be coming up correctly sized - presumably the default implementation of UserControl is figuring out some kind of size based on the contained controls. But you can't AutoSize the columns or rows in your sample beyond that since your properrty settings don't allow the user to resize rows or columns. And you are not even overring GetPreferredSize on the UserControl.So I am not sure what you are asking.
In earlier sample that I have posted is the same one which you have attached in your response and plus I have added code related to AutoSizeHeightOnly property through which label height get autosized which was not happening previously. Now, if you observe yellow highlighted cell values in screenshot Which is posted in my last reply, you will find that texts in label is not getting displayed fully as cell is not getting resized and texts within Label is so long that it requires cell resize as well I guess to display full text values within.
So, I need to resize usercontrol/ultra grid cell/labels accordingly so that it can displays full length of label value data which is there in last sample attached. Some of the cell is having values as below.
e.g. "888 aaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbb ccccccccccc eddddddddddddd 123457888\n(140011-24558667 %)"
So, 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, it helps to understand the actual issue now.
Can you pls help here - if you can provide updated sample with the same.
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.
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.