This is a migrated thread and some comments may be shown as answers.

Update a gridview with new columns

2 Answers 102 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Quan
Top achievements
Rank 1
Quan asked on 17 Jul 2015, 04:26 PM

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 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 21 Jul 2015, 02:18 PM
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
0
Quan
Top achievements
Rank 1
answered on 21 Jul 2015, 02:43 PM

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,

Tags
GridView
Asked by
Quan
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Quan
Top achievements
Rank 1
Share this question
or