This question is locked. New answers and comments are not allowed.
I have a very specific problem, so please try to understand the issues it relates to.
I am logging activities for users accross dates.
An activity can be authorized and has a related value.
Take a look at this table:
That means that on the the 3rd of January, Mark was active with a value of 8 and authorized, while Kirk was active with a value of 4, not authorized. On Jan 1, Kirk was not active at all. I hope the table makes sense.
The underlying data looks like this.
Now, I am trying to show this data in a RadGridView with three specific and mandatory requirements:
1) The number of users must remain variable. In other words, I don't know exactly how many columns will I need at compile time.
2) I must be able to set a different background color for cells that are not authorized (IsAuthorized == false). I don't want to display (A) in results, that's only indicative for this example. I want the background color changed appropriately instead.
3) Data must be sortable by all columns, both by time and by any of the user column.sortable
If it can't be done by using this approach (List<Double?> + ValueConverter), what changes would I have to do to be able to satisfy all three requirements?
(I've seen the Telerik's video example that shows how to style the cell by using a DataTemplate and StyleSelectors, but it was binding to a known double property in DataTemplate. I don't have a known property that represents the value, but a list of them.)
I am logging activities for users accross dates.
An activity can be authorized and has a related value.
Take a look at this table:
Mark Jack Kirk
1/1/2012 12 (A) 11 (A)
1/2/2012 18 15 4 (A)
1/3/2012 8 (A) 6 (A) 4
The underlying data looks like this.
public
class
Activity
{
public
String User {
get
;
set
; }
public
DateTime Time {
get
;
set
; }
public
Double? Value {
get
;
set
; }
public
Boolean IsAuthorized {
get
;
set
; }
}
Therefore, there is an instance of the Activity for each Time-User pair.
Now, I am trying to show this data in a RadGridView with three specific and mandatory requirements:
1) The number of users must remain variable. In other words, I don't know exactly how many columns will I need at compile time.
2) I must be able to set a different background color for cells that are not authorized (IsAuthorized == false). I don't want to display (A) in results, that's only indicative for this example. I want the background color changed appropriately instead.
3) Data must be sortable by all columns, both by time and by any of the user column.sortable
I've tried to create a class that represents a Grid row, that has a dynamic number of values, something like this:
public
class
ActivitiesDataRow
{
public
DateTime TimeStamp {
get
;
set
; }
public
List<
string
> ColumnHeaders {
get
;
set
; }
public
List<
double
?> Values {
get
;
set
; }
}
Then I create rows from all the activities. I turn off the auto-generation of columns, and make them manually, setting them like this:
List<Activity> activities =
new
List<Activity>();
List<ActivitiesDataRow> activityRows =
new
List<ActivitiesDataRow>();
// ...
// ...
List<String> users = activities.Select(a => a.User).Distinct().ToList();
for
(
int
i = 0; i < numberOfUsers; i++)
{
GridViewDataColumn col =
new
GridViewDataColumn();
// Get the names of the users, they are in the same order as
// their values in ActivitiesDataRow
col.Header = userNames[i];
col.DataType =
typeof
(ActivitiesDataRow);
Binding bnd =
new
Binding(
"Values"
);
bnd.Converter =
new
ActivityDataRowCollectionConverter();
bnd.ConverterParameter = i;
col.DataMemberBinding = bnd;
gridView.Columns.Add(col);
}
public
class
ActivityDataRowCollectionConverter : IValueConverter
{
public
object
Convert(
object
value, Type targetType,
object
parameter, CultureInfo culture)
{
// Since "Values" property is bound, the value is the List<Double?>
return
(value
as
List<Double?>)[(
int
)parameter];
}
}
How can I make it so that background color is set depending on the IsAuthorized value?
If it can't be done by using this approach (List<Double?> + ValueConverter), what changes would I have to do to be able to satisfy all three requirements?
(I've seen the Telerik's video example that shows how to style the cell by using a DataTemplate and StyleSelectors, but it was binding to a known double property in DataTemplate. I don't have a known property that represents the value, but a list of them.)