Back to Devexpress

DxGrid.MakeCellVisible(Int32, String) Method

blazor-devexpress-dot-blazor-dot-dxgrid-dot-makecellvisible-x28-system-dot-int32-system-dot-string-x29.md

latest6.1 KB
Original Source

DxGrid.MakeCellVisible(Int32, String) Method

Navigates to the cell displayed at the intersection of the specified row and data column.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public void MakeCellVisible(
    int visibleIndex,
    string fieldName
)

Parameters

NameTypeDescription
visibleIndexInt32

A row visible index.

| | fieldName | String |

A column field name.

|

Remarks

The Grid uniquely identifies each data cell by its row and column. To navigate to a data cell, pass the data row’s visible index and column field name to the MakeCellVisible method. To navigate to a group cell, pass the group row’s visible index and any field name to this method.

Note

The Grid bound to an Instant Feedback Data Source or GridDevExtremeDataSource loads data asynchronously in small portions (instead of the entire dataset). Before you call the MakeCellVisible method, call the WaitForRemoteSourceRowLoadAsync(Int32) method to ensure that the specified data row is loaded.

The MakeCellVisible method does nothing in the following cases:

When parameters are valid, the MakeCellVisible method performs the following actions:

  1. If the row is on another page, navigates to that page and updates the PageIndex property.
  2. Scrolls the Grid horizontally/vertically until the cell appears.

The following code snippet displays buttons that navigate to the first/last data cells:

razor
@inject WeatherForecastService ForecastService

<DxGrid Data="@Data" @ref="MyGrid">
    <Columns>
        <DxGridDataColumn FieldName="Date" DisplayFormat="D" />
        <DxGridDataColumn FieldName="TemperatureC" Caption="@("Temp. (\x2103)")" Width="120px" />
        <DxGridDataColumn FieldName="TemperatureF" Caption="@("Temp. (\x2109)")" Width="120px" />
        <DxGridDataColumn FieldName="Forecast" />
        <DxGridDataColumn FieldName="CloudCover" />
    </Columns>
    <ToolbarTemplate>
        <DxToolbar>
            <DxToolbarItem Text="First Cell" Click="@(() => MyGrid.MakeCellVisible(0, "Date"))" />
            <DxToolbarItem Text="Last Cell" 
                Click="@(() => MyGrid.MakeCellVisible(MyGrid.GetVisibleRowCount()-1, "CloudCover"))" />
        </DxToolbar>
    </ToolbarTemplate>
</DxGrid>

@code {
    IGrid MyGrid { get; set; }
    IEnumerable<WeatherForecast> Data { get; set; }

    protected override void OnInitialized() {
        Data = ForecastService.GetForecast();
    }
}
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, 150).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>();

Implements

MakeCellVisible(Int32, String)

See Also

MakeCellVisibleAsync(Object, String)

MakeDataItemVisibleAsync(Object)

MakeRowVisible(Int32)

DxGrid Class

DxGrid Members

DevExpress.Blazor Namespace