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
You could use the UltraControlContainerEditor to place a control in a cell. So, you could, for example, create a control that has two textboxes or a textbox and a label or something like so that you display two pieces of information in the cell with different fonts or formatting. But there are a few caveats to be aware of with this approach: - First, the cell itself only contains a single value. So you would need to either parse that value or get the additional data from somewhere else. - Second, it can be a bit tricky to set up the UltraControlContainerEditor if you've never done it before, so you'd have to check the documentation and samples on how to do it correctly.
Can you pls provide some sample where multiple texts , image and button controls are getting added in same cell using UltraControlContainerEditor.
I have gone through some of the examples like below where per cell - only one control is shown how to be added.
https://ko.infragistics.com/help/winforms/wincontrolcontainereditor-embed-any-control-within-wingrid-cell-using-ultracontrolcontainereditor-component
A cell can only contain a single value. So you would need to work out how to break up a single value into multiple pieces of text. There are an number of ways you could do this, but it would depend a lot on what your data is on how it relates to the other pieces of data.You could use a delimited string of some kind, for example. Of you could have a column your grid that is some kind of object with multiple properties on it. The challenge in that case would be how to relate that object to your database/back end - assuming it even has a back end and isn't just run-time data. Regarding placing multiple controls in a cell, the UltraControlContainerEditor has ONE RenderingControl and ONE EditingControl. But you could create a control or a UserControl that is contains several over controls, like a couple of TextBoxes, for example. You still have to handle everything through a SINGLE property, but again, that property could be a delimited string which then gets parsed into the separate TextBoxes and re-combined. Or it could be an object with multiple properties on it. I don't think we have any samples of this on-hand. And it would be tricky to set up, quite frankly. There's a lot of infrastructure you would need to handle like INotifyPropertyChange on both the object and it's sub-objects. It's really hard for me to guide you here without knowing a lot more about exactly what you are trying to achieve, what the data is, how the different pieces of the data relate to each, etc.
I used UltraFormattedTextEditor in cell to display formatted text containing text, image and button within. for first record in grid if it contains image then it seems its not converting text properly to display. the same code works fine for other cells of the same grid.
see above - yellow highlighted text has issue - where it displays img tag and not actual image. in below row, where it displays 780 properly with red image besides.
below is code for the same.
private void uRGrid_InitializeRow(object sender, InitializeRowEventArgs e) { UltraGridBand m_band = e.Row.Band; Infragistics.Win.Appearance appearance01 = new Infragistics.Win.Appearance(); Infragistics.Win.Appearance appearance02 = new Infragistics.Win.Appearance(); appearance01.BackColor = Color.White; appearance01.FontData.Name = new Font("Trebuchet MS", 9F).ToString();//, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))).ToString(); appearance02.BackColor = Color.Red; appearance02.FontData.Name = new Font("Trebuchet MS", 7F).ToString();//, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))).ToString();
//_uRGrid.UseAppStyling = false; //_uRGrid.DisplayLayout.Appearance = appearance02; try { for (int i = 1; i < m_band.Columns.Count - (CintRGridColumnsToHide - 1); i++) { string myValue = (string)e.Row.Cells[i].Value; myValue = myValue.Replace("&", "&"); myValue = myValue.Replace("'", "'"); myValue = myValue.Replace("\"", """); myValue = myValue.Replace("<", "<"); myValue = myValue.Replace(">", ">");
m_band.Columns[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText; e.Row.Cells[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText; string strrValue = myValue; string strrValOnly = string.Empty; string strRefRangeWithUnit = string.Empty; string strxmlRefRangeWithUnit = string.Empty; int foundRefRangeUnit = strrValue.IndexOf("\n"); if (foundRefRangeUnit > 0) { //it means unit ref range string is present so format it with 7 font size strRefRangeWithUnit = strrValue.Substring(foundRefRangeUnit); //strRefRangeWithUnit = strRefRangeWithUnit.Replace("&", "&"); //strRefRangeWithUnit = strRefRangeWithUnit.Replace("\"", """); //strRefRangeWithUnit = strRefRangeWithUnit.Replace("'", "'"); //strRefRangeWithUnit = strRefRangeWithUnit.Replace("<", "<"); //strRefRangeWithUnit = strRefRangeWithUnit.Replace(">", ">"); if (!string.IsNullOrEmpty(strRefRangeWithUnit)) { strrValOnly = strrValue.Substring(0, foundRefRangeUnit); strxmlRefRangeWithUnit = "<span style=\"font-size:7pt;\">" + strRefRangeWithUnit + "</span>"; strxmlRefRangeWithUnit = strxmlRefRangeWithUnit.Replace("\n", "<br/>"); //strrValue = strrValue.Substring(0, foundRefRangeUnit + 1) + "<span style=\"font-size:7pt;\">" + strRefRangeWithUnit + "</span>"; } }
//string strRefRangeWithUnit = FormatReferenceRangeForDisplay(strLowerBound, strUpperBound, strUoM);
//e.Row.Cells[0].Value = "<font size=\"7.25pt\">This way the\n text size is altered even\n when the cell is not in edit mode.</font>"; //e.Row.Cells[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText; //e.Row.Cells[i].Value = myValue + "<span style=\"font-size:5.25pt;\">
My Tes</span>"; UltraFormattedTextEditor uViewHistoryTextEditor = new UltraFormattedTextEditor(); UltraFormattedTextEditor ultraFormattedTextEditor = new UltraFormattedTextEditor();
string abn = (string)e.Row.Cells[i + 2].Value; string strHasrCorrectionHistory = (string)e.Row.Cells[i + 4].Value.ToString().ToUpper(); bool isFullEditorDisplay = true; StringBuilder sb = new StringBuilder(); string imageString = string.Empty; switch (abn.ToUpper()) { case "H": imageString = GetImageTag(ImageServer.GetImage("r_H")); sb.Append(imageString); e.Row.Cells[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText; //e.Row.Cells[i].Value = e.Row.Cells[i].Value + sb.ToString(); //e.Row.Cells[i].Appearance.Image = ImageServer.GetImage("r_High"); //e.Row.Cells[i].Appearance.ImageHAlign = HAlign.Right; //e.Row.Cells[i].Appearance.ImageVAlign = VAlign.Top; //e.Row.Cells[i].CellDisplayStyle = CellDisplayStyle.FullEditorDisplay; break; case "L": imageString = GetImageTag(ImageServer.GetImage("r_L")); sb.Append(imageString); e.Row.Cells[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText; //e.Row.Cells[i].Value = e.Row.Cells[i].Value + sb.ToString(); //e.Row.Cells[i].Appearance.Image = ImageServer.GetImage("r_Low"); //e.Row.Cells[i].Appearance.ImageHAlign = HAlign.Right; //e.Row.Cells[i].Appearance.ImageVAlign = VAlign.Top; //e.Row.Cells[i].CellDisplayStyle = CellDisplayStyle.FullEditorDisplay; break; case "HH": imageString = GetImageTag(ImageServer.GetImage("r_C")); sb.Append(imageString); e.Row.Cells[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText; ////e.Row.Cells[i].Value = e.Row.Cells[i].Value + sb.ToString(); ////e.Row.Cells[i].Appearance.Image = ImageServer.GetImage("r_CriticalHigh"); ////e.Row.Cells[i].Appearance.ImageHAlign = HAlign.Right; ////e.Row.Cells[i].Appearance.ImageVAlign = VAlign.Top; ////e.Row.Cells[i].CellDisplayStyle = CellDisplayStyle.FullEditorDisplay; break; default: //e.Row.Cells[i].CellDisplayStyle = CellDisplayStyle.FormattedText; isFullEditorDisplay = false; break; } if (foundRefRangeUnit > 0) { m_band.Columns[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText; if (!string.IsNullOrEmpty(sb.ToString())) { ultraFormattedTextEditor.Text = strrValOnly?.Trim() + sb.ToString().Trim() + strxmlRefRangeWithUnit?.Trim(); ultraFormattedTextEditor.Value = strrValOnly?.Trim() + sb.ToString().Trim() + strxmlRefRangeWithUnit?.Trim(); e.Row.Cells[i].Value = strrValOnly?.Trim() + sb.ToString().Trim() + strxmlRefRangeWithUnit?.Trim(); e.Row.Cells[i].EditorComponent = ultraFormattedTextEditor; e.Row.Cells[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText; } else { e.Row.Cells[i].Value = strrValOnly?.Trim() + strxmlRefRangeWithUnit?.Trim(); ultraFormattedTextEditor.Text = strrValOnly?.Trim() + strxmlRefRangeWithUnit?.Trim(); ultraFormattedTextEditor.Value = strrValOnly?.Trim() + strxmlRefRangeWithUnit?.Trim(); e.Row.Cells[i].EditorComponent = ultraFormattedTextEditor; e.Row.Cells[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText; }
} else { if (!string.IsNullOrEmpty(sb.ToString())) { ultraFormattedTextEditor.Text = myValue?.Trim() + sb.ToString().Trim(); ultraFormattedTextEditor.Value = myValue?.Trim() + sb.ToString().Trim(); e.Row.Cells[i].Value = myValue?.Trim() + sb.ToString().Trim(); e.Row.Cells[i].EditorComponent = ultraFormattedTextEditor; e.Row.Cells[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText; } else { if (string.Compare(myValue, e.Row.Cells[i].Value?.ToString()) > 0) { ultraFormattedTextEditor.Text = myValue?.Trim(); ultraFormattedTextEditor.Value = myValue?.Trim(); e.Row.Cells[i].Value = myValue?.Trim(); e.Row.Cells[i].EditorComponent = ultraFormattedTextEditor; e.Row.Cells[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText; } } }
string strAdditionalrData = e.Row.Cells[i + 5].Text; int isrOverFlow = 0; if (string.IsNullOrEmpty(strAdditionalrData) == false) { string[] arrayOfAdditionalrData = strAdditionalrData.Split(new char[] { '|' }); foreach (string strrData in arrayOfAdditionalrData) { string[] keyValuePair = strrData.Split(new char[] { '=' }); if (keyValuePair[0] == "rOverFlow") { isrOverFlow = int.Parse(keyValuePair[1]); break; } } } if (strHasrCorrectionHistory == "TRUE" || isrOverFlow == 1)// || foundRefRangeUnit > 0) { if (strHasrCorrectionHistory == "TRUE") { } EditorButton btnViewHistoryEditor = new EditorButton(); btnViewHistoryEditor.AccessibleName = "btnhasrCorrectionHistory"; btnViewHistoryEditor.Tag = "btnhasrCorrectionHistory"; btnViewHistoryEditor.Appearance.Image = ImageServer.GetImage("His"); btnViewHistoryEditor.Appearance.ImageHAlign = HAlign.Right; btnViewHistoryEditor.Appearance.ImageVAlign = VAlign.Top; btnViewHistoryEditor.ButtonStyle = UIElementButtonStyle.Borderless; btnViewHistoryEditor.Appearance.BackColor = Color.Transparent; uViewHistoryTextEditor.ButtonsRight.Add(btnViewHistoryEditor);
if (isrOverFlow == 1) { EditorButton btnExpandr = new EditorButton(); btnExpandr.AccessibleName = "btnEx"; btnExpandr.Tag = "btnEx"; btnExpandr.Appearance.Image = ImageServer.GetImage("r_Comments"); btnExpandr.Appearance.ImageHAlign = Infragistics.Win.HAlign.Left; btnExpandr.Appearance.ImageVAlign = Infragistics.Win.VAlign.Middle; btnExpandr.ButtonStyle = UIElementButtonStyle.Borderless; btnExpandr.Appearance.BackColor = Color.Transparent; uViewHistoryTextEditor.ButtonsLeft.Add(btnExpandr); }
e.Row.Cells[i].EditorComponent = uViewHistoryTextEditor;
_uRGrid.DisplayLayout.Bands[0].Columns[i].ButtonDisplayStyle = Infragistics.Win.UltraWinGrid.ButtonDisplayStyle.Always; e.Row.Cells[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText;
} else { if (isFullEditorDisplay == false) { e.Row.Cells[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText; } } if (e.Row.Cells[i].Text.Length > 8) {
m_band.Columns[i].CellMultiLine = DefaultableBoolean.True; m_band.Columns[i].Width = 200; } e.Row.PerformAutoSize(); // Auto resize row once value assigned to row...
i += (CintRGridColumnsToHide - 1); } } catch (Exception ex) { } }
can you pls let me know the issue here.
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.
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.
Hi Mike,
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.