Posted 18 November 2024, 5:02 am EST
- Updated 18 November 2024, 5:07 am EST
Hi,
Thanks for sharing the video with us. I was able to replicate the behaviour at my end. I am currently investigating the issue at my end.
As a workaround, you could use the C1CheckBox in the GridColumn and then set the value for the CheckBox. Refer to the attached sample.
<FlexGrid ItemsSource="forecasts" @ref="grid" Style="new C1Style() { Height = 300}"
CellFactory="cellFactory" AutoGenerateColumns="false">
<FlexGridColumns>
@if (forecasts != null && forecasts.Length > 0)
{
foreach (var prop in typeof(WeatherForecast).GetProperties())
{
if (prop.Name == "IsEnabled")
{
<GridColumn Header="@prop.Name" HorizontalAlignment="C1HorizontalAlignment.Center">
<CellTemplate>
@{
var weatherForecast = context as WeatherForecast;
<C1CheckBox IsChecked="weatherForecast.IsEnabled" IsCheckedChanged="@(v=> weatherForecast.IsEnabled = v.Value)"></C1CheckBox>
}
</CellTemplate>
</GridColumn>
}
else
{
<GridColumn Binding="@prop.Name" Header="@prop.Name"></GridColumn>
}
}
}
</FlexGridColumns>
</FlexGrid>
Also, for setting the value of the CheckBox using the “Space” key, you could override the “OnKeyDown” method of the GridCellFactory, and then change the underlying value.
Refer to the following code snippet:
public class MyCellFactory : GridCellFactory
{
protected override bool OnKeyDown(KeyboardEventArgs e)
{
if (e.Code == "Space")
{
// Here goes custom logic
GridCellRange cursorRange = Grid.CursorRange;
if (Grid.Columns[cursorRange.Column].Header == "IsEnabled")
{
WeatherForecast rowValue = ((WeatherForecast)(Grid.GetCellValue(GridCellType.Cell, cursorRange)));
bool isEnabled = (bool)(Grid.SelectedItem as WeatherForecast).IsEnabled;
(Grid.SelectedItem as WeatherForecast).IsEnabled = !isEnabled;
Grid.Refresh(GridCellType.Cell, cursorRange);
return false;
}
}
return base.OnKeyDown(e);
}
}
Please note that currently the FlexGrid doesn’t handle the default behaviour of the browser on “Space” press and scrolls the Grid. You could check for the column “isEnabled” and then prevent this behaviour using the JavaScript.
You could use the above solutions. Further, I will update you on the above behaviour after my investigations.
Regards,
Ankit
CheckBox_Column.zip