Update a gridview with new columns

3 posts, 0 answers
  1. Quan
    Quan avatar
    2 posts
    Member since:
    Jul 2015

    Posted 17 Jul 2015 Link to this post

    Hi,
    I have a gridview to show only some columns of a table the first time, and some others after the first time. The problem is if I do not include all columns in the first query when the query is changed the gridview do not update those columns.
    Please assist me in this regard
    Thank you

    XAML
    <telerik:RadGridView Grid.Row="1" Grid.ColumnSpan="4" Name="GridNewDate" ItemsSource="{Binding Path=dataTable}" ActionOnLostFocus="None"
                                             AutoGenerateColumns="False" HorizontalAlignment="Left" CanUserInsertRows="False" CanUserDeleteRows="True"
                                             ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible" Margin="0,5,0,0"   CanUserFreezeColumns="True">
                            <telerik:RadGridView.Columns>
                                <telerik:GridViewDataColumn Header="A"                           DataMemberBinding="{Binding A}" />
                                <telerik:GridViewDataColumn Header="B"                           DataMemberBinding="{Binding B}" />
                                <telerik:GridViewDataColumn Header="C"                            DataMemberBinding="{Binding C}" />
                                <telerik:GridViewDataColumn Header="D"                            DataMemberBinding="{Binding D}" />
                            </telerik:RadGridView.Columns>
                        </telerik:RadGridView>

    C# (Model)
    DataTable dataTable;

    If (firstTime)
    {
    _View.GridNewDate.ItemsSource = GetData(“SELECT A, C FROM T”);
                    firsTime = false;
    }
    else
    {
    _View.GridNewDate.ItemsSource = GetData(“SELECT A, B, C, D FROM T”);

    }

  2. Stefan X1
    Admin
    Stefan X1 avatar
    521 posts

    Posted 21 Jul 2015 Link to this post

    Hello Quan,

    Since you are using a DataTable object, can you please try setting the ItemsSource of RadGridView to be DataTable.DefaultView instead of DataTable?

    If this does not fix the problem, would it be possible for you to shed some light when is the logic for setting the ItemsSource of RadGridView fired? Is the if-else statement passing correctly?

    Best Regards,
    Stefan X1
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Quan
    Quan avatar
    2 posts
    Member since:
    Jul 2015

    Posted 21 Jul 2015 in reply to Stefan X1 Link to this post

    Hi,

    The problem was solved with the suggestion of setting the ItemsSource of RadGridView to be a DataTable.DefaultView instead of Datatable.

    Thanks a lot.
    Best Regards,

Back to Top