How to control number of allowed checkbox states?
I am using the silverlight 4 toolkit gridcontrol and I'm using auto generated columns. My boolean field is showing up as a tri-state checkbox (true, false, null).
public bool? Enabled { get; set; }
How to I force it to use only two states (true/false). Changing the field type is not an option at this time.
@Bala
[XAML]
<sdk:DataGrid Grid.Row="1" Grid.Column="1" x:Name="liveGrid"
HorizontalAlignment="Center"
VerticalScrollBarVisibility="Hidden" HorizontalContentAlignment="Center"
ItemsSource="{Binding MyDatasource}" AutoGenerateColumns="True" />
Just a thought: does a UIHint data annotation exist for this, maybe?
Possible Solution
Following @Rick I have a working solution:
[XAML]
<sdk:DataGrid Grid.Row="1" Grid.Column="1" x:Name="liveGrid"
HorizontalAlignment="Center"
VerticalScrollBarVisibility="Hidden" HorizontalContentAlignment="Center"
AutoGeneratingColumn="viewModel_AutoGeneratingColumn"
ItemsSource="{Binding MyDatasource}" AutoGenerateColumns="True" />
[View]
private void viewModel_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
if ("Enabled" == e.PropertyName)
{
开发者_如何学运维 DataGridCheckBoxColumn checkBox = e.Column as DataGridCheckBoxColumn;
checkBox.IsThreeState = false;
}
}
You can continue to use auto-generated columns and customize those columns. Here is an article that describes how to customize auto-generated columns:
- How to: Customize Auto-Generated Columns in the DataGrid Control
The technique mainly consists of hooking the DataGrid.AutoGeneratingColumn
event.
If you follow that procedure, all you need to do is find your column (e.g. by property name) and set IsThreeState
to false
:
- DataGridCheckBoxColumn.IsThreeState Property
精彩评论