Set GridView ItemSource to Datatable

2 posts, 0 answers
  1. Eric Klein
    Eric Klein avatar
    183 posts
    Member since:
    Aug 2009

    Posted 12 Apr 2012 Link to this post

    I have a GridVIew that I want to populate with the results of a StoredQuery that returns a list of string.
    I have the following
    public DataTable GetLoadedTransactionFiles()
           {
               using (FamilyOfficeDataContext db = new FamilyOfficeDataContext())
               {
                   var query = db.GetTransactionFileLoad();
                    
                   DataTable dt = new DataTable();
                   dt.Columns.Add("FileLoaded", typeof(string));
     
                   foreach (var file in query)
                   {
                       DataRow newRow = dt.NewRow();
                       newRow["FileLoaded"] = file.LoadedFile;
                       dt.Rows.Add(newRow);
                   }
                   return dt;
               }
           }

    When I set the grivview itemsource like so

    FilesLoadedGrid.ItemsSource = gl.GetLoadedTransactionFiles().DefaultView;


    I see the grid has two rows but the filename is not displayed.
    the  xaml is as follows
    <telerik:RadGridView HorizontalAlignment="Left" Margin="153,26,0,0" Name="FilesLoadedGrid" VerticalAlignment="Top" Height="233" Width="439" AutoGenerateColumns="False"
                                 CanUserFreezeColumns="False" CanUserReorderColumns="False" CanUserResizeColumns="False"  RowIndicatorVisibility="Collapsed" ShowGroupPanel="False"
                                  AlternationCount="2"  AlternateRowBackground="Cornsilk"  Deleting="FileDeleted" >
                <telerik:RadGridView.Columns>
                    <telerik:GridViewColumn >
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <telerik:RadButton Content="Delete" Command="telerikGrid:RadGridViewCommands.Delete" CommandParameter="{Binding }" />
                            </DataTemplate>
                        </telerik:GridViewColumn.CellTemplate>
                    </telerik:GridViewColumn>
                    <telerik:GridViewDataColumn Header="Loaded File" Name="FileLoaded" DataMemberBinding="{Binding Path= LoadedFile}"  Width="*"  IsReadOnly="true">
                    </telerik:GridViewDataColumn>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>

    What am I missing?

  2. Eric Klein
    Eric Klein avatar
    183 posts
    Member since:
    Aug 2009

    Posted 12 Apr 2012 Link to this post

    Nevermind I see the error.  The fieldname in the binding was wrong.  Once I changed it to match what was in the datatable it worked.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top