This is a migrated thread and some comments may be shown as answers.

GridView Conditional Formatting Control

24 Answers 647 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Troy
Top achievements
Rank 1
Troy asked on 09 Mar 2018, 01:57 AM

Screenshot

From this image, as you can see I have a formatting value condition if the cell is >= 80. If my cell values are strings, how do I control the conversion to an integer value in this case or have control of how this validation takes place? -8000 is nowhere near being >= 80...

Also - How do I control everything else in that Window? It isn't even using my application icon for the form icon. :/

24 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 12 Mar 2018, 12:07 PM
Hello, Troy,

Thank you for writing.  
 
According to the provided information it seems that you use a text column to store numeric values. It would be much better to use a GridViewDecimalColumn. The conditional formatting rule you add will use the cell's value which is text. Thus, the 'greater than' condition use the text comparison of the values. If you need to apply the formatting considering the numeric value, feel free to use the column which is designed to handle such cell values.

As to the icon of the dialog, You can subscribe to the RadGridView.ConditionalFormattingFormShown event and set the ConditionalFormattingForm.Icon property: 
private void radGridView1_ConditionalFormattingFormShown(object sender, EventArgs e)
{
    ConditionalFormattingForm form = sender as ConditionalFormattingForm;
    if (form != null)
    {
        form.Icon = Properties.Resources.ProgressIcon;
    }
}

I hope this information helps. Should you have further questions I would be glad to help. 
 
 Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Troy
Top achievements
Rank 1
answered on 12 Mar 2018, 02:57 PM

No that is definitely not the answer. It's a numeric value formatted as a string in different numeric representations. I need it to be formatted into a string depending on the format property of the object itself (binary, hex, etc...). I don't want to just show a standard decimal value.

 

Thanks for the info on the icon though.

0
Troy
Top achievements
Rank 1
answered on 12 Mar 2018, 02:59 PM
It appears there's a format string property for that type of cell, but there's no format for a binary literal AFAIK which is the problem, and another format is also a %/percent value from 0-100% being the range of a 16-bit value in my case.
0
Troy
Top achievements
Rank 1
answered on 12 Mar 2018, 03:09 PM

(I wish we could edit posts here) :(

 

I also have to mention that the values stored in the gridview are objects of a base class where the "value" of each object is essentially a bool, a ushort, or a string. It would be nice to still be able to use the >/</<=/>=/etc.. operators on the objects that have the ushort value. Otherwise, as a last resort is there a way to disable this functionality and just keep the string-based conditional formatting options?

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 15 Mar 2018, 06:43 AM
Hello, Troy,      

Thank you for writing back. 

If you use numeric values, you can use a GridViewDecimalColumn and specify the desired format by setting the GridViewDecimalColumn.FormatString. You can find below a sample code snippet how to apply hexadecimal format:

GridViewDecimalColumn decimalColumn = this.radGridView1.Columns["Id"] as GridViewDecimalColumn;
decimalColumn.FormatString = "{0:X}";



You can refer to the following MSDN article which lists the available numeric formats that RadGridView supports: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings

As to the conditional formatting for the ushort column, I have logged it in our feedback portal. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item.

I have also updated your Telerik points.

Currently, the possible solution that I can suggest is to use the CellFormatting event.

I hope this information helps. If you have any additional questions, please let me know. 

 Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Troy
Top achievements
Rank 1
answered on 23 Mar 2018, 03:50 AM

Yes but I have custom string formats that I would like to have available that aren't default formats.

 

Hex ("0x0A" or "0Ah")

Decimal ("10")

Binary ("1010b")

 

Additionally, that data column will also contain actual string data depending on the type of object to be represented in that row which is not a numeric value converted to a string but an actual string value of that type of object.

 

I have a program which essentially keeps track of "Digital", "Analog" and "Serial" object types. The datatype for the value of each of these objects is essentially a bool, a ushort, and a string. I need to keep that column representing the object as a string.

0
Troy
Top achievements
Rank 1
answered on 23 Mar 2018, 03:53 AM
I don't think there's an answer to my problem using this control, as I'd need multiple formatters here - each internal object has a different value datatype that isn't always a numeric type.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 26 Mar 2018, 01:58 PM
Hello, Troy, 

If you need to have different formatting for the cells belonging to a certain column, it is suitable to use the CellFormatting event. In the event handler you can set the CellElement.Text property to the desired text considering the column and row. Thus, you can apply any format that you need. 

I hope this information helps. If you have any additional questions, please let me know. 

Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Troy
Top achievements
Rank 1
answered on 26 Mar 2018, 07:53 PM

Hi Dess,

I have the formatting specified from the perspective of the objects being added to the cell in that column which all derive from a base class. The ToString() method is overrided to look at the internal Format enum value of the object to determine how to display the string representation of that object. The values that is shown in that cell for each of the 3 derived classes however (before formatting to System.String) are respectively bool, ushort, and byte[]. I have the formatting in place already, and would like the formatting "information" to be specified on the object side rather than the grid view side so that they can maintain their formatting individually and between being removed and re-added to the control since the information will be directly bound to that object. This still doesn't quite solve the question for me as to how I can use those object types that had an initial value of maybe bool and ushort with the numeric conditional formatting functionality, where false could potentially represent 0, and true as 1, then the ushort values as their numeric values and ignore the derived objects that have a value of byte[].

Basically the column cell type is for string data because I can't have a numeric cell type since one of the object values is of type byte[] and the other being a bool. The data added to the cell is whatever gets returned from the ToString() of that object (overriden).

 

I hope this kind of explains my problem now..

0
Troy
Top achievements
Rank 1
answered on 26 Mar 2018, 07:57 PM
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 28 Mar 2018, 11:33 AM
Hello, Troy, 

The provided screenshot was really helpful. If the column contains different objects you can create a TypeConverter that will be applied to the column. Then, in the TypeConverter you can use the implemented ToString method in order to return the desired value when the converter needs a string value. The following help article demonstrates how you can apply a custom TypeConverter to a grid's column:
https://docs.telerik.com/devtools/winforms/gridview/columns/converting-data-types

The exact conversion depends on the custom objects' implementation that you have. If you are still experiencing any further difficulties, it would be greatly appreciated if you can provide a sample project demonstrating the undesired behavior that you are currently facing. Thus, we would be able to investigate the precise case and assist you further. Thank you in advance.

I hope this information helps. If you have any additional questions, please let me know. 

Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Troy
Top achievements
Rank 1
answered on 30 Mar 2018, 04:14 AM
Hold on, so if I use a TypeConverter do I have to do a type conversion for all derived object types from the base class object over to a numeric value so that the column can be a numeric cell type for me to use the conditional formatting for number information? Or can this remain as a string data cell for that column and the conditional formatting functionality will use the TypeConverter internally to deal with this data? If I have to use a TypeConverter to bring that column over to a numeric cell type, then I wouldn't know how to convert the numeric value back to something like a byte array. I'm just really confused here.
0
Troy
Top achievements
Rank 1
answered on 30 Mar 2018, 04:16 AM

In my base class I just bind the ToString() to a property so that it's easy enough to bind my collection of the base object to a column.

public string Data => ToString();

Then internally within each derived class the ToString() is overloaded.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Apr 2018, 07:11 AM
Hello, Troy,   

The easiest way to control what to be displayed in the grid cells is to use the CellFormatting event and construct the desired cell's text from the associated record. The second possible approach is to use a TypeConverter applied to the column. However, it would be necessary to convert each of the custom types to the value required by the column. 

If you have ToString() method for each of the custom objects, I would recommend you to use the CellFormatting event and set the cell's Text property to the result returned by the ToString() method. Thus, you will display the desired value. 

I hope this information helps. If you have any additional questions, please let me know. 

Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Troy
Top achievements
Rank 1
answered on 03 Apr 2018, 04:17 PM

"However, it would be necessary to convert each of the custom types to the value required by the column. " - This is what I'm talking about though... So this won't work. I have an objects that I want to display the data for of types; bool, ushort, and byte[]. If I want to use the numeric semantics for conditional formatting on the objects that have internal value datatypes of bool and ushort, I'm betting that I need to use the GridViewDecimalColumn for the cells there, and bool could be converted to a 1 or a 0, but I CAN'T convert a byte[] to a numeric value and back again to be represented in that column; I would lose all the information. And if I used a numeric cell type then I would lose all of the string-based conditional cell formatting too I'm assuming.

 

I'm going to try using the CellFormatting event though just to see how that behaves.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 04 Apr 2018, 01:36 PM
Hello, Troy,   

I hope that the CellFormatting event would be the easiest way to achieve displaying the desired text in the grid cells. Thus, you will store the original values that you have in the cells and simply replace the text. Thus, you will be able to use the implemented ToString method of your custom objects.

If you have any additional questions, please let me know. 

Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Troy
Top achievements
Rank 1
answered on 05 Apr 2018, 05:25 AM

Signal (base class)

DigitalSignal -> derives from Signal class
    - Value (type bool)
    - Format -> (Not applicable)

AnalogSignal -> derives from Signal class
    - Value (type ushort)
    - Format -> AnalogSignalFormat enum type
    
SerialSignal -> derives from Signal class
    - Value (type byte[])
    - Format -> AnalogSignalFormat enum type

GridView is a collection of base class Signal type.

I want the set Format property to determine the signal formatting for the string representation of AnalogSignal and SerialSignal derived types (which is 2 entirely different enum types, and DigitalSignal has no Format property)... However I also want to be able to use the Conditional Formatting feature for this data column and not have it throw an exception when I try to use the number-based logic in that dialog (<, >, <=, >=, etc...) and have it apply to my AnalogSignal cells, and maybe the DigitalSignal cells where true could equate to 1, and false with 0 perhaps. Then the string-based conditional formatting logic to apply to the textual representation of whatever is seen in all cells that correspond with all 3 types of Signal's (my derived types).

If my Data property which is declared in my Signal class, which returns the overriden ToString() value returned from my derived class changes to 'System.Object' for instance and then my values are returned that way, where boxing/unboxing performance loss is involved, still... How would I know which row/cell corresponds with a particular signal type unless I map the object type for that cell from bool -> DigitalSignal, ushort -> AnalogSignal, and byte[] -> SerialSignal
as this seems kind of hacky?

I'm still having quite a bit of trouble thinking about a way that I can incorporate all of this into the mix because my derived classes have some very different behavior between each other but they need to be recognized under the Signal hierarchy so that I can have them all within the same collection/container. I use reflection to grab the enum values from the Format property for displaying in my combobox based on the Signal pulled from my SignalCollection, which works for the 2-way binding in my Format column (I can set the format by typing the name in there), but this gets tricky with being able to use the conditional formatting features the way I would like to use them since my GridView stores a collection of the base Signal class, and the Format enum between all 3 derived types is unique, but this is the value I need to use to determine the formatting for that derived signal type, and as a string, it doesn't help me much when I want to be able to apply numeric formatting rules to my AnalogSignal type.

Look at the attached image to see what I'm trying to *FIX*... To an end-user the screenshot results would make absolutely no sense.

0
Troy
Top achievements
Rank 1
answered on 05 Apr 2018, 05:32 AM
I want to be able to provide the conditional formatting feature but it's just not reliable enough to provide to my end-users the way it is. And I'm unsure on how to interface with it properly.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 06 Apr 2018, 11:11 AM
Hello, Troy,   
  
When you bind RadGridView to a collection of a basic class, all properties that are available in this basic class will be displayed as columns in the grid. In order to determine which row corresponds to a particular signal type, it is necessary to access the DataBoundItem and cast it to the respective derivative. Thus, you can extract any specific information that is stored in the object itself. Otherwise, you don't know what is the exact object's type.

Note that the CellFormatting event has a higher priority than the conditional formatting. I suppose that you apply some style to the grid cells in the CellFormatting event. That is why you may not obtain the desired styling with the conditional formatting. I would recommend you to use one of the two approaches for the cells' customizations. 

As to the error, is it possible to provide a sample project that demonstrates the undesired behavior that you are facing? Thus, we would be able to investigate the precise case and assist you further. Thank you in advance.

I am looking forward to your reply.

Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Troy
Top achievements
Rank 1
answered on 06 Apr 2018, 05:25 PM
"it is necessary to access the DataBoundItem and cast it to the respective derivative" - Okay so how can the conditional formatting functionality determine which cells can be cast to an AnalogSignal to use the ushort for the logic, while still maintaining the display of the overriden ToString() for each of my derived objects in that cell which is displayed? That's the problem I'm trying to overcome still.

"As to the error, is it possible to provide a sample project that
demonstrates the undesired behavior that you are facing? Thus, we would
be able to investigate the precise case and assist you further. Thank
you in advance." - it is a private commercial project that I'm working on but it won't work that well unless you have the proprietary hardware that it connects to. I can provide the definitions privately somehow for the signal object types?
0
Troy
Top achievements
Rank 1
answered on 06 Apr 2018, 05:26 PM
Thanks for all your patience with this issue I'm trying to get my head around by the way...
0
Accepted
Dimitar
Telerik team
answered on 10 Apr 2018, 08:11 AM
Hi Troy,

Dess is out of the office this week so I will handle this case. 

In general, a single column holds data from a single data type (int, string) that can be compared. In your case, the cells have different data types and our logic cannot handle such comparison. Dess suggestion was to convert to a single data type in order to be able to use the conditional formatting. If this is not possible you can handle the formatting manually and instead of using conditional formatting create a separate form that will allow you to set the condition. Then you can manually style the cells using the CellFormatting event or the Style property. I have attached a small project that shows a sample implementation. 

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Troy
Top achievements
Rank 1
answered on 12 Apr 2018, 06:31 PM

AHHH... I now understand what was meant. I think this will be much easier for me to comprehend as well and balance exactly which features I want for the formatting since it's kind of unique in my case. Thanks for that, I seen this notification in my email for a while but I've been super busy this week so I haven't had any time to try this, but I think this answers my problem without a doubt.

 

I'll now mark this as solved. Many thanks!

0
Dimitar
Telerik team
answered on 13 Apr 2018, 06:36 AM
Hi Troy,

Take all the time to examine this and do not hesitate to contact us if you have other questions.
 
Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Troy
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Troy
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or