Click here to Skip to main content
15,886,773 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I am developing wpf application using C# without using any framework.until now i successfully performed following task on Datagrid.
1.Displaying data in Data-grid by binding with database table
2.Getting the selected row data from Data-grid based on primary key

Here is code for my Data-grid
XML
<DataGrid x:Name="dtgsecutity"  HorizontalAlignment="Left" Height="168" Margin="614,513,0,0" ItemsSource="{Binding Path=Security_details}" VerticalAlignment="Top" Width="344">
   <DataGrid.Columns>
   <DataGridTextColumn Width="30" Header="S\No" Binding="{Binding Path=id, Mode=TwoWay}" />
   <DataGridTextColumn Width="45" Header="Code" Binding="{Binding Path=Code, Mode=TwoWay}" />
   <DataGridTextColumn Width="80" Header="Description" Binding="{Binding Path=Description, Mode=TwoWay}" />
   <DataGridTextColumn Width="40" Header="Rate" Binding="{Binding Path=Rate, Mode=TwoWay}" />
   <DataGridTextColumn Width="30" Header="Qty" Binding="{Binding Path=Qty, Mode=TwoWay}" />
   <DataGridTextColumn Width="60" Header="Amount" Binding="{Binding Path=Amount, Mode=TwoWay}" />
   <DataGridTextColumn Width="60" Header="Remarks" Binding="{Binding Path=Remarks, Mode=TwoWay}" />
   </DataGrid.Columns>
   </DataGrid>

Now my concerns with this data-grid are:

When No db table is loaded in data-grid :

If my data-grid is unloaded with db tables it is not editable. How i can create row by making it editable? And How i can pragmatically retrieve all those multiple newly created rows for insert command?

When table is loaded in data-grid :

1. If my data-grid is loaded with db tables and i try to add new rows it is not showing new rows in vertical manner rather it shows new rows in horizontal manner. How i can set data-grid to add new row to in vertical manner?
2. And How i can pragmatically retrieve all those multiple updated rows for update command?

Please help me for accomplishing this task without using any framework.Thanks .
Posted
Updated 20-Nov-13 18:34pm
v3
Comments
[no name] 21-Nov-13 22:47pm    
Are you using DataTable or ObservableCollection? which collection type is binded to your dataGrid? and why you need to show row in vertical manner? if you want to show it in vertical manner you to write a template ( override the existing).

1 solution

<datagridtextcolumn width="30" header="S\No" binding="{Binding Path=id, Mode=TwoWay}">

If id is the primary key, the mode should be one way; besides it should be clearly noted on your data source "Security_details".

Make sure you have primary key and the system knows that from the data source "Security_details" .
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900