Back to Devexpress

IGridSelectionColumn Interface

blazor-devexpress-dot-blazor-1811dbeb.md

latest5.3 KB
Original Source

IGridSelectionColumn Interface

An interface that defines a Grid selection column‘s API members (properties and methods).

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public interface IGridSelectionColumn :
    IGridColumn

The following members return IGridSelectionColumn objects:

Remarks

We recommend that you use the IGridSelectionColumn interface when you access a Grid selection column’s API members in any of the following cases:

  • You use the @ref attribute to reference a Grid selection column. For example, you set or change values of the Grid column’s parameters outside the markup.
  • You access a SelectionColumn object from templates or event handlers.
  • You access elements of the Grid column collection. For example, the collection that is returned by the GetColumns() method.

In all other cases, bind your data to column parameters.

The following code snippet allows you to display/hide the selection column on a button click. Note that when you change a column parameter that causes the Grid to update (the column’s Visible property in the example below), enclose your code between the BeginUpdate() and EndUpdate() method calls.

razor
@inject WeatherForecastService ForecastService

<DxGrid Data="@forecasts"
        @ref="MyGrid">
    <Columns>
        <DxGridSelectionColumn Width="150px" @ref=SelectionColumn/>
        <DxGridDataColumn Caption="Date" FieldName="Date" />
        <DxGridDataColumn Caption="Temperature" FieldName="TemperatureF" />
    </Columns>
</DxGrid>

<DxButton Text="Show/Hide the Selection Column" Click=OnButtonClick />

@code {
    private WeatherForecast[]? forecasts;
    IGrid MyGrid { get; set; }
    IGridSelectionColumn SelectionColumn { get; set; }

    protected override async Task OnInitializedAsync() {
        forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
    }

    void OnButtonClick() {
        MyGrid.BeginUpdate();
        SelectionColumn.Visible = !SelectionColumn.Visible;
        MyGrid.EndUpdate();
    }
}
csharp
using System;

public class WeatherForecast {
    public DateTime Date { get; set; }
    public int TemperatureC { get; set; }
    public double TemperatureF => Math.Round((TemperatureC * 1.8 + 32), 2);
    public string Forecast { get; set; }
    public string CloudCover { get; set; }
    public bool Precipitation { get; set; }
csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

public class WeatherForecastService {
    private List<WeatherForecast> Forecast { get; set; }

    private static string[] CloudCover = new[] {
        "Sunny", "Partly cloudy", "Cloudy", "Storm"
    };

    Tuple<int, string>[] ConditionsForForecast = new Tuple<int, string>[] {
        Tuple.Create( 22 , "Hot"),
        Tuple.Create( 13 , "Warm"),
        Tuple.Create( 0 , "Cold"),
        Tuple.Create( -10 , "Freezing")
    };

    public WeatherForecastService() {
        Forecast = CreateForecast();
    }

    private List<WeatherForecast> CreateForecast() {
        var rng = new Random();
        DateTime startDate = DateTime.Now;
        return Enumerable.Range(1, 15).Select(index => {
            var temperatureC = rng.Next(-10, 30);
            return new WeatherForecast {
                Date = startDate.AddDays(index),               
                TemperatureC = temperatureC,
                CloudCover = CloudCover[rng.Next(0, 4)],
                Precipitation = Convert.ToBoolean(rng.Next(0, 2)),
                Forecast = ConditionsForForecast.First(c => c.Item1 <= temperatureC).Item2
            };
        }).ToList();
    }

    public IEnumerable<WeatherForecast> GetForecast() {
        return Forecast.ToArray();
        // ...
    }
csharp
// ...
builder.Services.AddSingleton<WeatherForecastService>();

See Also

IGridSelectionColumn Members

DevExpress.Blazor Namespace