Hello,
I have four buttons in my aplication: (Save, Cancel, Add, Delete), xamdatagrid and several textboxes. Each of textbox is binding with ActiveRecord.Cells[..] from grid. When i click in Add button - grid add new row (in id column is -1 value). Next i have to submit changes, so click Save button. In the SQL database row is added - column id is a primary key an set identity, so have new value increment by 1, but in xamdatagrid id value is still -1. Nothing not change any effects, even this:
grid.datasource=null;grid.datasource=DataTable;
What can i do?
thanks for quickly answer, bellow is example code
//reading data from source
ProjektDB.profilAdapter.Fill(ProjektDB.projektDS.Profil);ProjektDB.projektAdapterManager.ProfilTableAdapter = ProjektDB.profilAdapter;gridProfil.DataSource = ProjektDB.projektDS.Profil;
//Click on Add button invoke this public static void Dodaj(object focus, ProjektDataSet.ProfilDataTable tablica) { ProjektDataSet.ProfilRow profil = tablica.NewProfilRow(); profil.Nazwa = "_aaaaaa"; tablica.AddProfilRow(profil);
aktywujOstatniRekord(ref SlownikKontrakty.Instance.gridProfil); ((System.Windows.Controls.TextBox)focus).SelectAll(); ((System.Windows.Controls.TextBox)focus).Focus(); } public static void aktywujOstatniRekord(ref XamDataGrid grid) { Record record = (grid.Records[grid.Records.Count - 1]); grid.Focus(); grid.ActiveRecord = record; record.IsSelected = true; record.IsActive = true; } //Click on Save button invoke this public static void Zapisz(ref XamDataGrid grid) { grid.ExecuteCommand(DataPresenterCommands.CommitChangesToActiveRecord); if (ProjektDB.projektDS.HasChanges()) { ProjektDB.projektAdapterManager.UpdateAll(ProjektDB.projektDS); Assergs.Windows.MessageBox.Show("Zmiany zostały zapisane.","Informacje",MessageBoxButton.OK,MessageBoxImage.Information); }
} in XAML:
<igDP:XamDataGrid Name="gridProfil" Theme="Office2k7Blue" Margin="3,3.19,3,60.81" GroupByAreaLocation="None" RecordContainerGenerationMode="PreLoad" ScrollingMode="Deferred" Height="550" > <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Settings> <igDP:FieldLayoutSettings AutoArrangeCells="Default" AutoGenerateFields="False" /> </igDP:FieldLayout.Settings> <igDP:FieldLayout.Fields> <igDP:Field Name="IdProfil" Label="ID"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" CellValuePresenterStyle="{StaticResource ReadOnly}" CellWidth="50" LabelWidth="50" /> </igDP:Field.Settings> </igDP:Field> ... <igDP:Field Name="h" Label="h" Visibility="Collapsed" > <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" CellValuePresenterStyle="{StaticResource ReadOnly}" CellWidth="0" LabelWidth="0" /> </igDP:Field.Settings> </igDP:Field> ... </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts>
And now binding...
<Grid DataContext="{Binding ElementName=gridProfil, Path=ActiveRecord}" Grid.Column="2" Margin="3"> ... <TextBox x:Name="txbNazwaPelna" Width="200" Grid.Column="1" Grid.Row="1" Text="{Binding Path=Cells[NazwaPelna].Value, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding ElementName=gridProfil, Path=ActiveRecord, Converter={x:Static conv:ConvertersHolder.convActiveRecord}}"/>
Hello wdryja,
This could be a couple of different things depending on how you are binding the grid and how you are adding the row. Do you have a code sample that you provide? You may also want to consider submitting a support request for someone to look at this in more detail.