Ad

Showing Only Some Part Of The List On The Grid Control

- 1 answer

Here is an exemplary code piece:

Model.cs

public class Datas
{
    public int Region;
    public int Frequency;
    public int Amplitude;
}

MainViewModel.cs

public Datas Data1;

public MainViewModel()
{
    DataList = new ObservableCollection<Datas>();   
    GetDatas();
}

public ObservableCollection<Datas> DataList { get; set; }

public void GetDatas()
{
    ...
    ...

    var command = new SqlCommand($"Select [Region], [Frequency], [Amplitude].. WHERE REGION = '{SelectedRegion}..");
    var dataReader = command.ExecuteReader();

    while (dataReader.Read())
    {
        var Data1 = new Datas();
        Data1.Region = dataReader["Region"];
        Data1.Frequency = dataReader["Frequency"];
        Data1.Amplitude = dataReader["Amplitude"];

        DataList.Add(Data1);
    }

    connection.close();
}

(I tried to use DevExpressMVVM tools.)

MainView.xaml

<dxg:GridControl ItemsSource = "{Binding DataList} ...../>

Now; I can see the table on the window with Region, Frequency, and Amplitude columns and their values. But I want only to show the 2 columns; maybe like Frequency and Amplitude.

What would be the most efficient way to do this?

Ad

Answer

In XAML or in code you can set the column visibility to hidden. If you give a name to your datagrid you can access his properties.

<dxg:GridControl Name="myDatagrid" ItemsSource = "{Binding DataList} ...../>

then in code :

myDataGrid.Columns[0].Visibility = Visibility.Hidden;
Ad
source: stackoverflow.com
Ad