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

Set GridView ItemSource to Datatable

1 Answer 27 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Eric Klein
Top achievements
Rank 1
Eric Klein asked on 12 Apr 2012, 08:48 PM
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?

1 Answer, 1 is accepted

Sort by
0
Eric Klein
Top achievements
Rank 1
answered on 12 Apr 2012, 08:56 PM
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.
Tags
GridView
Asked by
Eric Klein
Top achievements
Rank 1
Answers by
Eric Klein
Top achievements
Rank 1
Share this question
or