I have a button in my grid that popups up a popup with a user control that allows the user to pick from another datagrid record to associate with that column. This works fine for editing existing records and also the first time I do a New Record. The problem is, if you Add New Record, save, and then Add New Record again, it seems the grid believes I am still working on the previously added New Record. I have went as far as rebinding the datagrid, but it still has the same problem. So the user can only do one time without problems.
So let me try to explain. I have a single Column with a button.
<igDP:Field Name="MediaItemID" Label="Referenced Resource"> <igDP:Field.Settings> <igDP:FieldSettings CellValuePresenterStyle="{StaticResource ResourceItemTemplate}" CellWidth="250" LabelWidth="150" /> </igDP:Field.Settings> </igDP:Field>
The associated style
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="ResourceItemTemplate"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <StackPanel Orientation="Horizontal"> <TextBox BorderThickness="0" Text="{Binding Path=DataItem.MediaItemID,Converter={StaticResource convMediaID}}" IsReadOnly="True" TextWrapping="Wrap" Width="200"/> <Button x:Name="ResourceItemButton" Click="ResourceItemButton_Click" Width="35" HorizontalAlignment="Right" Style="{DynamicResource BlackButtonFlexStyle}"> <Button.Effect> <DropShadowEffect/> </Button.Effect> <Image Height="24" Width="24" Margin="0,0,0,0" Source="/Common/Images/HotCell.ico" VerticalAlignment="Center" ToolTip="Click to show items to chose from" /> </Button> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style>
Now the code behind. This is basically how I make all the popup stuff
private void ResourceItemButton_Click(object sender, RoutedEventArgs e) { try { Cursor = Cursors.Wait; var btnsel = sender as Button; DataRecord selRecord = null; GeoObjectMediaItem selGeoObjectMediaItem = null;
if (btnsel.DataContext is DataRecord) { selRecord = btnsel.DataContext as DataRecord; selGeoObjectMediaItem = selRecord.DataItem as GeoObjectMediaItem; } if (btnsel.DataContext is GeoObjectMediaItem) { selGeoObjectMediaItem = btnsel.DataContext as GeoObjectMediaItem; }
if (selGeoObjectMediaItem == null) { var newitem = new GeoObjectMediaItem(); Guid newid = Guid.NewGuid(); newitem.ID = newid; newitem.GeoObjectID = _item.Tag; newitem.GeoObjectType = _item.GeoObjectID; btnsel.DataContext = newitem;
var newpop = new PopResource(newitem, _ctx); newpop.Owner = CurrentSession.CurrentShell; newpop.ShowDialog();
if (newpop.DialogResult.HasValue && newpop.DialogResult.Value) { _ctx.GeoObjectMediaItems.InsertOnSubmit(newitem); _collMedia.Add(newitem); _ctx.SubmitChanges(); } } else { var newpop = new PopResource(selGeoObjectMediaItem, _ctx); //newpop.Owner = CurrentSession.BaseShell; newpop.ShowDialog(); } } catch (Exception ex) { Helper.SetError(ex); } finally { gridMain.DataSource = null; gridMain.DataSource = new BindingList<GeoObjectMediaItem>(_collMedia); Cursor = Cursors.Arrow; } }
HI,
Near the end of your routine execute the following DataPresenterCommand.
xgrid1.ExecuteCommand(DataPresenterCommands.CommitChangesToActiveRecord);
Sincerely, MattDeveloper Support Engineer
I am just following up on this post.
Please let me know if you need further assistance.
Sincerely, Matt Developer Support Engineer