I have a grid that represents six months of data, where each cell represents a day. The grid has 6 rows and 33 columns (Month, Days 1 through 31, Total). How would I dynamically disable those cells that do not represent a valid date (e.g. Feb 30, Feb 31, Apr 31, etc.) so that the user cannot enter data in them? The grid will either show the first half of a year, or the second half of a year (Jan - Jun, or Jul - Dec).
13 Answers, 1 is accepted
0
Hi Steve Dentel,
Maya
the Telerik team
A possible approach may be to use the IsReadOnlyBinding that can be set to True for those cells you do not want to edit. You may take a look at our online documentation for a reference.
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Steve
Top achievements
Rank 2
answered on 19 Jan 2011, 11:09 PM
I looked at the example (XAML). How would I do this in the code behind? What about the fact that I am trying to disable different cells (days), depending on the row (month). Take a look at the screen shot showing my grid. Each hand drawn red 'X' represents a date that I don't want to allow the user to edit.
0
Hello Steve Dentel,
In this case IsActive is a property of the business object. You may take a look at this forum thread for a reference and a sample project demonstrating how you may use the IsReadOnlyBinding.
Another possible approach may be to use a CellStyleSelector and color those cells which do not have any values for example. You may take a look at our online documentation and demos for further information.
All the best,
Maya
the Telerik team
You may define the IsReadOnlyBinding in the code-behind like follows:
GridViewDataColumn column = new GridViewDataColumn();
column.DataMemberBinding = new Binding("Name");
column.IsReadOnlyBinding = new Binding("IsActive");
this.clubsGrid.Columns.Add(column);
In this case IsActive is a property of the business object. You may take a look at this forum thread for a reference and a sample project demonstrating how you may use the IsReadOnlyBinding.
Another possible approach may be to use a CellStyleSelector and color those cells which do not have any values for example. You may take a look at our online documentation and demos for further information.
All the best,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Steve
Top achievements
Rank 2
answered on 20 Jan 2011, 05:40 PM
Hello Maya,
Can you make the TelerikSL2010Q2 solution available that was shown in the RadGridView - Style and Template Selectors video for Silverlight and WPF?
Thanks,
Steve
Can you make the TelerikSL2010Q2 solution available that was shown in the RadGridView - Style and Template Selectors video for Silverlight and WPF?
Thanks,
Steve
0
Hi Steve Dentel,
Maya
the Telerik team
May you provide a bit more details which video are you referring to ? Do you require a sample demonstrating the usage of Style and Template Selectors ?
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Steve
Top achievements
Rank 2
answered on 20 Jan 2011, 06:29 PM
Hi Maya,
It is the video on this page: http://www.telerik.com/help/silverlight/gridview-cell-style-selector.html
Thanks,
Steve
It is the video on this page: http://www.telerik.com/help/silverlight/gridview-cell-style-selector.html
Thanks,
Steve
0
Hi Steve Dentel,
Maya
the Telerik team
You may find a sample project attached.
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Steve
Top achievements
Rank 2
answered on 20 Jan 2011, 06:53 PM
Hi Maya,
That is not the solution displayed in the video...see attached screen shot. A suggestion: when training videos are published on your website that utilize a specific VS solution, please also publish the solutions shown in the video.
Thank you.
Steve
That is not the solution displayed in the video...see attached screen shot. A suggestion: when training videos are published on your website that utilize a specific VS solution, please also publish the solutions shown in the video.
Thank you.
Steve
0
Steve
Top achievements
Rank 2
answered on 20 Jan 2011, 10:52 PM
Hi Maya,
Would you please provide the solution referenced in the video?
Thanks,
Steve
Would you please provide the solution referenced in the video?
Thanks,
Steve
0
Accepted
Hello Steve Dentel,
Maya
the Telerik team
I am sending you the sample project used in the video.
I hope that helps.
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Tyree
Top achievements
Rank 2
answered on 24 Jan 2011, 02:53 PM
If you set the IsReadOnlyBinding={Binding DateString,Converter={StaticResource IsInvalidDate}}
Where your DateString is not actually as obviously it would error, then in the converter you test if its a valid date...if not return true. Of course thats assuming your doing some sort of MVVM or add the property to your row item. If your trying to build a grid via the code behind you can do something more direct like {Binding Month /* 2/1/2011 */, Converter={StaticResource IsDateNotInMonth}, ConverterParamenter=29 /* day number */} checking if the parameter is valid for the month in question.
Where your DateString is not actually as obviously it would error, then in the converter you test if its a valid date...if not return true. Of course thats assuming your doing some sort of MVVM or add the property to your row item. If your trying to build a grid via the code behind you can do something more direct like {Binding Month /* 2/1/2011 */, Converter={StaticResource IsDateNotInMonth}, ConverterParamenter=29 /* day number */} checking if the parameter is valid for the month in question.
0
Steve
Top achievements
Rank 2
answered on 31 Jan 2011, 10:49 PM
Thank you for providing the solution shown in the video. After some trial and error, I am using the conditional style converter with three numeric converters. Below is the xaml for the UserControl.Resources section
Here's the xaml on the grid for the three days that I want to check:
And here is the first converter...the others are similar. In the code below, ExerciseDate is always set to the first day of the month...e.g. 2/1/2011
<
UserControl.Resources
>
<
Style
x:Key
=
"Day29StyleIsValid"
TargetType
=
"rgv:GridViewCell"
>
<
Setter
Property
=
"IsEnabled"
Value
=
"True"
/>
</
Style
>
<
Style
x:Key
=
"Day29StyleIsNotValid"
TargetType
=
"rgv:GridViewCell"
>
<
Setter
Property
=
"IsEnabled"
Value
=
"False"
/>
</
Style
>
<
local:Day29Converter
x:Key
=
"zDay29Converter"
/>
<
local:ConditionalStyleSelector
x:Key
=
"Day29StyleSelector"
ConditionConverter
=
"{StaticResource zDay29Converter}"
>
<
local:ConditionalStyleSelector.Rules
>
<
local:ConditionalStyleRule
Style
=
"{StaticResource Day29StyleIsValid}"
>
<
local:ConditionalStyleRule.Value
>
<
sys:Boolean
>True</
sys:Boolean
>
</
local:ConditionalStyleRule.Value
>
</
local:ConditionalStyleRule
>
<
local:ConditionalStyleRule
Style
=
"{StaticResource Day29StyleIsNotValid}"
>
<
local:ConditionalStyleRule.Value
>
<
sys:Boolean
>False</
sys:Boolean
>
</
local:ConditionalStyleRule.Value
>
</
local:ConditionalStyleRule
>
</
local:ConditionalStyleSelector.Rules
>
</
local:ConditionalStyleSelector
>
<
Style
x:Key
=
"Day30StyleIsValid"
TargetType
=
"rgv:GridViewCell"
>
<
Setter
Property
=
"IsEnabled"
Value
=
"True"
/>
</
Style
>
<
Style
x:Key
=
"Day30StyleIsNotValid"
TargetType
=
"rgv:GridViewCell"
>
<
Setter
Property
=
"IsEnabled"
Value
=
"False"
/>
</
Style
>
<
local:Day30Converter
x:Key
=
"zDay30Converter"
/>
<
local:ConditionalStyleSelector
x:Key
=
"Day30StyleSelector"
ConditionConverter
=
"{StaticResource zDay30Converter}"
>
<
local:ConditionalStyleSelector.Rules
>
<
local:ConditionalStyleRule
Style
=
"{StaticResource Day30StyleIsValid}"
>
<
local:ConditionalStyleRule.Value
>
<
sys:Boolean
>True</
sys:Boolean
>
</
local:ConditionalStyleRule.Value
>
</
local:ConditionalStyleRule
>
<
local:ConditionalStyleRule
Style
=
"{StaticResource Day30StyleIsNotValid}"
>
<
local:ConditionalStyleRule.Value
>
<
sys:Boolean
>False</
sys:Boolean
>
</
local:ConditionalStyleRule.Value
>
</
local:ConditionalStyleRule
>
</
local:ConditionalStyleSelector.Rules
>
</
local:ConditionalStyleSelector
>
<
Style
x:Key
=
"Day31StyleIsValid"
TargetType
=
"rgv:GridViewCell"
>
<
Setter
Property
=
"IsEnabled"
Value
=
"True"
/>
</
Style
>
<
Style
x:Key
=
"Day31StyleIsNotValid"
TargetType
=
"rgv:GridViewCell"
>
<
Setter
Property
=
"IsEnabled"
Value
=
"False"
/>
</
Style
>
<
local:Day31Converter
x:Key
=
"zDay31Converter"
/>
<
local:ConditionalStyleSelector
x:Key
=
"Day31StyleSelector"
ConditionConverter
=
"{StaticResource zDay31Converter}"
>
<
local:ConditionalStyleSelector.Rules
>
<
local:ConditionalStyleRule
Style
=
"{StaticResource Day31StyleIsValid}"
>
<
local:ConditionalStyleRule.Value
>
<
sys:Boolean
>True</
sys:Boolean
>
</
local:ConditionalStyleRule.Value
>
</
local:ConditionalStyleRule
>
<
local:ConditionalStyleRule
Style
=
"{StaticResource Day31StyleIsNotValid}"
>
<
local:ConditionalStyleRule.Value
>
<
sys:Boolean
>False</
sys:Boolean
>
</
local:ConditionalStyleRule.Value
>
</
local:ConditionalStyleRule
>
</
local:ConditionalStyleSelector.Rules
>
</
local:ConditionalStyleSelector
>
</
UserControl.Resources
>
Here's the xaml on the grid for the three days that I want to check:
<
telerik:GridViewDataColumn
x:Name
=
"Day29Col"
DataMemberBinding
=
"{Binding Path=Day29, Mode=TwoWay}"
Header
=
"29"
IsFilterable
=
"False"
IsSortable
=
"False"
CellStyleSelector
=
"{StaticResource Day29StyleSelector }"
/>
<
telerik:GridViewDataColumn
x:Name
=
"Day30Col"
DataMemberBinding
=
"{Binding Path=Day30, Mode=TwoWay}"
Header
=
"30"
IsFilterable
=
"False"
IsSortable
=
"False"
CellStyleSelector
=
"{StaticResource Day30StyleSelector }"
/>
<
telerik:GridViewDataColumn
x:Name
=
"Day31Col"
DataMemberBinding
=
"{Binding Path=Day31, Mode=TwoWay}"
Header
=
"31"
IsFilterable
=
"False"
IsSortable
=
"False"
CellStyleSelector
=
"{StaticResource Day31StyleSelector }"
/>
And here is the first converter...the others are similar. In the code below, ExerciseDate is always set to the first day of the month...e.g. 2/1/2011
public class Day29Converter : IValueConverter
{
public object Convert(object value,
Type targetType,
object parameter,
System.Globalization.CultureInfo culture)
{
ParticipantExerciseDetail ped = value as ParticipantExerciseDetail;
if (ped != null)
{
// Add 28 days to the ExerciseDate, which is always day 1.
// If the 29th is a valid date, then the month
// component of day will not have changed.
DateTime day = new DateTime();
day = ped.ExerciseDate.AddDays(28);
return day.Month == ped.ExerciseDate.Month ? true : false;
}
return null;
}
public object ConvertBack(object value,
Type targetType,
object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
0
Jerry T.
Top achievements
Rank 1
answered on 01 Jul 2011, 04:24 PM
How would one setup a CellStyleSelector using the MVVM method?
I was looking at the attached project from the Posted on Jan 20, 2011 post and it looks like the general idea I need to use but we're using MVVM so I don't have direct access from the codebehind.
Or, is there some way to access the grid's data thru the grid's properties/methods?
I was looking at the attached project from the Posted on Jan 20, 2011 post and it looks like the general idea I need to use but we're using MVVM so I don't have direct access from the codebehind.
Or, is there some way to access the grid's data thru the grid's properties/methods?