Skip to content

UltraGrid Cell Customization

New Discussion
ferdin
ferdin asked on Feb 18, 2013 11:48 AM

Hi Everyone

I have Ultragrid and i have column called text where there is some text and other columns like font-family,style,size,weight,color,backcolor,border and bordercolor. If i change some values in this it should get reflected in the text column according to the chosen values from all these.

I tried to do it in but i couldn get it i dont know where i have gone wrong.

Is there any way to do it.

Colud someone help me please

Thanks in advance

Ferdin

Sign In to post a reply

Replies

  • 0
    Matt Snyder
    Matt Snyder answered on Nov 26, 2008 3:35 PM

    Ferdin,

    You could use the InitializeRow event to check when the value in your formatting columns have been updated and then change the value of the cell in the Text column of that row accordingly.  The best way to do this would be to use a Style on the Text column of FormattedText or FormattedTextEditor.  You would likely need to build the string of formatting yourself, though.  

    The structure that I'm referring to for the InitializeRow event is:

     private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
    {
        string fontFamily = e.Row.Cells["FontFamily"].Value.ToString();
        string fontSize= e.Row.Cells["FontSize"].Value.ToString();

        // Build the formatted string here

        e.Row.Cells["Text"].Value = myFormattedText;
    }

    For an example of what string to build, you could add an UltraFormattedTextEditor to your form and click on the UITypeEditor (the button with '…') on the Value property, then use the dialog that shows up to create a formatted string.  You can see the raw value that is generated there to see how it is structured.  You can also find a list of supported xml tags here.

    -Matt

    • 0
      ferdin
      ferdin answered on Nov 27, 2008 11:43 AM

      Hi Matt

      Thanks for your support.

      I tried to do so in the method which you suggested but the InitializeRow event gets fired up by the time the grid loads.

      I need to have column which is in the grid that updates to the Fonts choosen from another cell in the same grid.

      I tried this event in CellChange

      Here comes the following code

      ultraGrid.DisplayLayout.Override.EditCellAppearance.ForeColor =

      SystemColors.Desktop;

      ultraGrid.DisplayLayout.Override.EditCellAppearance.BackColor = System.Drawing.

      Color.Black;

      After writing this code the ForeColor and BackColor changes for the Active Cell which has focus.

      I also tried this too

      ultraGrid.Rows[Row].Cells[2].EditorControlResolved.BackColor = System.Drawing.

      Color.Black;

      ultraGrid.Rows[Row].Cells[2].EditorControl.BackColor = System.Drawing.

      Color.Black;

      These two lines throws errors like this

      Object reference not set to an instance of an object.

      Could you please help me

      Thanks in advance

      Ferdin

       

       

      • 0
        Mike Saltzman
        Mike Saltzman answered on Dec 1, 2008 7:48 PM

        It looks like you are using the wrong appearances. You need to set the Appearance on the cell.

        If you are using InititializeRow, you would do something like this:

        e.Row.Cells["Text"].Appearance.BackColor = (Color)e.Row.Cells["BackColor"].Value;

        e.Row.Cells["Text"].Appearance.ForeColor = (Color)e.Row.Cells["Color"].Value;

        You will, of course, need to check for null in the value of the Color, BackColor, etc. cells.

      • 0
        ferdin
        ferdin answered on Dec 17, 2008 12:12 PM

        Mike,

        Thanks a lot for your post. It worked fine with me. I tried to use this same in the cell change event but i got exceptions later i casted the type and worked perfect with me.

        Can you give me some ideas how to acheive for Font Family, Font Size, Font Style, Font weight and Border.

        Thanks

        Ferdin

         

      • 0
        Mike Saltzman
        Mike Saltzman answered on Dec 17, 2008 3:22 PM

        Hi Ferdin,

        [quote user="ferdin"]Can you give me some ideas how to acheive for Font Family, Font Size, Font Style, Font weight and Border.[/quote]

        Appearance.FontData.Name,

        Appearance.FontData.SizeInPoints,

        Appearance.BorderColor, 

        etc.

      • 0
        ferdin
        ferdin answered on Dec 18, 2008 9:11 AM

        Mike,

        Thanks for it worked perfectly. I am jus missing how to set the FontWeight & Border for a particular cell. I dont see any of the properties to make it possible. Can you suggest me some ideas?

        Ferdin

      • 0
        Mike Saltzman
        Mike Saltzman answered on Dec 18, 2008 3:13 PM

        Hi Ferdin,

        I'm not sure what FontWeight is. I don't beleive there is any setting for that on the Appearance. 

        Regarding the borders, you really can't apply a border to a single cell, because a cell does not draw all 4 sides of it's border. If it did, then there would be a double-thick border between every two cells in the grid. A cell draws only one or two border sides and it relies on the adjacent cells to draw their borders. 

        The only way to draw a border around a cell would be to draw it yourself using a DrawFilter. 

         

      • 0
        ferdin
        ferdin answered on Dec 19, 2008 12:33 PM

        Mike

        Thanks for the reply it really helped me a lot

        Ferdin

         

    • 0
      Hieu Tran
      Hieu Tran answered on Feb 24, 2010 8:13 AM

      Hi Matt,

      Sorry for digging this up, but I encountered a problem when following your guide in this post. The grid shows original text with xml tags such as 222 <i>(Current)</i>, not the result I want 222 (Current). Do I have to enable any property of the grid (except CellDisplayStyle = CellDisplayStyle.FormattedText) to show formatted text?

       

      • 0
        Mike Saltzman
        Mike Saltzman answered on Feb 24, 2010 3:49 PM

        CellDisplayStyle is not what you want here. You need to set the Style property of the column to FormattedText or FormattedTextEditor (if you want editing).

      • 0
        Nitin Jain
        Nitin Jain answered on Feb 15, 2013 7:42 AM

        Hi,

        How can I change the font size for every cell. I tried to set CellAppearance.FontData.SizeInPoints = 7.25f, but it seems to be effective only when the cell is in edit mode, otherwise it comes to the normal text size as soon as I make the cell non-editable.

        Any ideas on this?

        Thanks,

        Nitin Jain

      • 0
        [Infragistics] Boris Toromanov
        [Infragistics] Boris Toromanov answered on Feb 15, 2013 8:04 AM

        Hello Nitin,

        Please try the following approach and let me know if it suits your needs:

                private void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)

                {

                    e.Row.Cells[0].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText;

                    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>";

                }

      • 0
        Nitin Jain
        Nitin Jain answered on Feb 15, 2013 8:09 AM

        Hi Boris,

        I need to apply on each and every cell. So can I do this on grid.DisplayLayout.Override.CellAppearance in grid initialize event?

        Thanks,

        Nitin Jain

      • 0
        [Infragistics] Boris Toromanov
        [Infragistics] Boris Toromanov answered on Feb 15, 2013 8:37 AM

        Hi Nitin,

        Yes, you could use this event in order to set the 'Style' of the entire column to formattedtext.

      • 0
        Nitin Jain
        Nitin Jain answered on Feb 15, 2013 9:36 AM

        You mean for each column I have to set style to some value like:

        grid.DisplayLayout.Bands[0].Columns[0].Style = ColumnStyle.FormattedTextEditor (//to enable editing)

        How can I set font size if the above is correct?

        Thanks,

        Nitin Jain

      • 0
        [Infragistics] Boris Toromanov
        [Infragistics] Boris Toromanov answered on Feb 15, 2013 10:59 AM

        Nitin,

        This is in order for the column to take such tags as <font>. The values of the cells are different for each cell and should be set separately, in the 'InitializeRow' event for example.

      • 0
        Nitin Jain
        Nitin Jain answered on Feb 15, 2013 11:08 AM

        Hi Boris,

        Don't we have any other way to resize the font as this would be messy to set Style for each column and then set value with this info for each column.

        Thanks,

        Nitin Jain

      • 0
        [Infragistics] Boris Toromanov
        [Infragistics] Boris Toromanov answered on Feb 15, 2013 11:14 AM

        Nitin,

        You could use Bands[0].Columns[0].CellAppearance.FontData.SizeInPoints = 15; in case you want every cell to have the same font size.

      • 0
        Nitin Jain
        Nitin Jain answered on Feb 15, 2013 11:27 AM

        Hi Boris,

        I think I am trying to solve the problem with wrong approach.

        The issue is, user wants to have a solid view of data. In other words the solution is to resize the columns width according to the cell data present in all the rows instead of changing the font size of cell (that anyway will not solve this issue), so that the width will be equal to the max. length of the data in any of the cell for that column.

        For that I tried PerformAutoResizeColumns, but there we have other issues with this approach:

        1. We have one column of type boolean, showing the cell as checkbox, hidden by default. On some action we unhide that column. But when I apply PerformAutoResize that column is still hidden.

        2. After applying PerformAutoResize, the data in some of columns is chopped off.

        Will appreciate if you can suggest anything on this?

        Thanks,

        Nitin Jain

      • 0
        [Infragistics] Boris Toromanov
        [Infragistics] Boris Toromanov answered on Feb 15, 2013 11:43 AM

        Hello Nitin,

        Did you try the different overloads of this method?

        If you use it this way: 

        e.Layout.Bands[0].PerformAutoResizeColumns(false, Infragistics.Win.UltraWinGrid.PerformAutoSizeType.VisibleRows, Infragistics.Win.UltraWinGrid.AutoResizeColumnWidthOptions.IncludeCells);.

        It should NOT take into account the hidden cells and should autosize to width only by the cell's contents.

        If this does not help, please attach a screenshot of the issue after using this code so I can take a look, something might come up on my mind.

      • 0
        Nitin Jain
        Nitin Jain answered on Feb 15, 2013 11:51 AM

        Hi Boris,

        I think I have a different ver. of Infragistics (//Infragistics ver. 8.3) as I have only 2 overloads for this function:

        PerformAutoResizeColumns(bool sizeHiddenColumns,PerformAutoSizeType performAutoSizeType)

        PerformAutoResizeColumns(bool sizeHiddenColumns,PerformAutoSizeType performAutoSizeType,bool includeHeader)

        Thanks,

        Nitin Jain

      • 0
        [Infragistics] Boris Toromanov
        [Infragistics] Boris Toromanov answered on Feb 15, 2013 11:57 AM

        Hi,

        So, isn't it working with (false, VisibleRows, false)? Could you please post a sample project which reproduces it, I am not sure how it behaves in v8.3 in your scenario. There should be a way to get the desired behavior even in v8.3, I am determined to find it, just need a project to work on.

      • 0
        Nitin Jain
        Nitin Jain answered on Feb 15, 2013 12:54 PM

        Hi Boris,

        I apologies, I cannot provide a sample as Infragistics is on client machine and I do not have permissions to upload any document from there.

        1. If I use the (false,VisibleRows,true), some data is chopped off that would be annoying for user.

        2. If I use (false,VisibleRows,false), and there is no data in the grid then the display is very weird, it resize all the columns to almost 0 size.

        3. If I use (true,VisibleRows,true/false), the hidden columns don't appear again.

        Thanks,

        Nitin Jain

      • 0
        [Infragistics] Boris Toromanov
        [Infragistics] Boris Toromanov answered on Feb 15, 2013 1:12 PM

        Hi Nitin,

        If you do not have the 'AutoResizeColumnWidthOptions' on the 'Override' object then I think that you should get the newest version of NetAdvantage.

        Another way would be to calculate manually the width of the columns – you should take the font size into account.

      • 0
        Nitin Jain
        Nitin Jain answered on Feb 15, 2013 1:21 PM

        Hi Boris,

        I cannot upgrade to the newest version of Infragistics.

        I would appreciate if you can provide some sample code for performing resize manually.

        Thanks,

        Nitin Jain

      • 0
        [Infragistics] Boris Toromanov
        [Infragistics] Boris Toromanov answered on Feb 15, 2013 1:28 PM

        Nitin,

        The following approach works just fine for me:

        foreach (UltraGridColumn col in ultraGrid1.DisplayLayout.Bands[0].Columns)
             col.Width = col.CalculateAutoResizeWidth(PerformAutoSizeType.VisibleRows, true);

        Please take a look at the sample attached to this post. If it does not work for you, please modify my sample so it reproduces the issue and send it back to me. I will be happy to take a look at it.

      • 0
        Nitin Jain
        Nitin Jain answered on Feb 15, 2013 1:53 PM

        Hi Boris,

        Thanks for the sample.

        I applied the changes in my code and there is an issue:

        The first column which is of boolean type and is showing a checkbox is distorted (Please see snapshot)

        Wondering even after passing the last param as true why this is happening.

        Thanks,

        Nitin Jain

      • 0
        [Infragistics] Boris Toromanov
        [Infragistics] Boris Toromanov answered on Feb 15, 2013 2:23 PM

        Nitin,

        This is how it looks in my sample, I also attached the sample itself, the version is 8.3:

      • 0
        Nitin Jain
        Nitin Jain answered on Feb 15, 2013 2:48 PM

        Hi Boris,

        In my app that column is hidden by default. But I think I can overcome this issue by applying this resize whenever the hidden property changes for that column.

        I am not able to mark your post as answer so that it will be useful for others too, may be because this is not my post initially.

        Thanks,

        Nitin Jain

      • 0
        [Infragistics] Boris Toromanov
        [Infragistics] Boris Toromanov answered on Feb 18, 2013 11:48 AM

        Hello Nitin,

        Thank you for the feedback.

        My answer will be marked by my superior.

        Could you please create new threads(questions), it would be easier for me to follow them and it will improve our search functionality for the other community members. Thank you in advance. Please let me know if something comes up!

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
ferdin
Favorites
0
Replies
30
Created On
Feb 18, 2013
Last Post
13 years, 1 month ago

Suggested Discussions

Tags

Created by

Created on

Feb 18, 2013 11:48 AM

Last activity on

Feb 19, 2026 8:09 AM