Empty Table for Data I/O

Alex_D

Member
Joined
Dec 26, 2019
Messages
6
Programming Experience
Beginner
Hi, I am new at C#.
Is there a way to create empty Excel-like table in XAML where I will be able to input data and perform some operations on them.
I was able to bind DataGrid to objects and put the data in the table from there. But I am looking for a way to have an empty table first and directly input(/process) data in there

Thanks in advance!
Alex
 
Do you mean blank as in completely free form generic columns named A, B, C, D, etc. ? Or blank as in no row data, but the column names and types are set by your code?
 
Thanks for the reply!
I mean, no data but the column names and types, as well as number of rows, being set by the code.
 
So what's wrong with binding an empty observable collection of a particular object type to the data grid. Just be sure to setup 2-way binding, and setting the property on the data grid to allow adding rows so that as new items are added, you are able to save the new objects that have been added/editted.
 
C#:
        <DataGrid x:Name="eDataGrid" AutoGenerateColumns="False" CanUserAddRows="True" Foreground="Magenta" HorizontalAlignment="Left" Height="224" Margin="10,35,0,0" VerticalAlignment="Top" Width="489">
            <DataGrid.Columns>
                <DataGridTextColumn Header="I am Header A" Width="*" x:Name="ColumnA" />
                <DataGridTextColumn Header="I am Header B" Width="*" x:Name="ColumnB" />
                <DataGridTextColumn Header="I am Header C" Width="*" x:Name="ColumnC" />
            </DataGrid.Columns>
        </DataGrid>
As per Skydivers instructions, you would simply do something like the above to formulate your structure for your DataGrid Table in XAML. However, you don't want to add items as suggested above, instead implement the INotifyPropertyChanged for your observable collection and then you can bind your data, but remember to set your DataGrid.ItemsSource to your IEnumerable collection and you're done. It would be more suitable if you show what you've tried.
 
Hi Both. Thanks a lot for suggestions.

I will try out. I hope I understood you right. I am a beginner in C# and my questions might sound a bit too simple.

Thanks a lot again!
BR, Alex
 
Back
Top Bottom