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

Deletion of Row from GridView

1 Answer 53 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gorakhnath Choudhary
Top achievements
Rank 1
Gorakhnath Choudhary asked on 17 Dec 2009, 10:42 AM
Hi,

I am facing a problem while deleting a record from the GridView, after clicking on the delete button, methods get executed and record is successfully deleted from the XML File and from the Observable collection property but the grid is not getting refreshed.  
could you please suggest me asap.

File Code:

Binding to grid using MVVM pattern i.e. datasource list is observable collection which assign to the view datacontext.

View Model Class:

public class ScenerioViewModel : ViewModelBase
    {
        private IScenerioRepository _repository;
        ObservableCollection<Scenerio> scenerio = new ObservableCollection<Scenerio>();
        #region Constructor
        public ScenerioViewModel (): this(new ScenerioRepository())
        {
            // Blank
        }
        public ScenerioViewModel(IScenerioRepository repository)
        {
            _repository = repository;
            GetAllRecords();
        }
        #endregion Constructor
        public ObservableCollection<Scenerio> OCScenario
        {
            get { return scenerio; }
        }
        
        private void GetAllRecords()
        {
            scenerio.Clear();
            List<Scenerio> scenerioList = _repository.GetAllRecords();
            foreach (Scenerio sce in scenerioList)
            {
                scenerio.Add(sce);
            }
        }

        private RelayCommand deleteData;
        public ICommand ICDeleteData
        {
            get
            {
                if (deleteData == null)
                {
                    deleteData = new RelayCommand(param => DeleteData());
                }
                return deleteData;
            }
        }

        private void DeleteData()
        {
            _repository.DeleteRecord(scenerio.FirstOrDefault());
            GetAllRecords();
        } 

XAML File code:
<telerik:RadGridView x:Name="YeildCurveGrid"  ItemsSource="{Binding Path=OCScenario/ListYeildCurve}" AutoGenerateColumns="False" DataLoadMode="Asynchronous"  ColumnWidth="*" RowIndicatorVisibility="Collapsed" IsFilteringAllowed="False" ShowGroupPanel="False" >
<telerik:GridViewDataControl.Columns>
 <telerik:GridViewDataColumn Header="Select" DataMemberBinding="{Binding IsSelected}" IsFilterable="False" IsSortable="False">
    <telerik:GridViewDataColumn.CellTemplate>
          <DataTemplate>
               <CheckBox IsChecked="{Binding IsSelected}"/>
         </DataTemplate>
   </telerik:GridViewDataColumn.CellTemplate>
 </telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Header="GUID" IsVisible="False" IsFilterable="False" DataMemberBinding="{Binding GUID}" IsReadOnly="True" IsSortable="False" ></telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Header="Code" IsFilterable="False" DataMemberBinding="{Binding CrncyCode}" IsReadOnly="True" IsSortable="False"  Background="BlanchedAlmond" ></telerik:GridViewDataColumn>
</telerik:GridViewDataColumn>
</telerik:GridViewDataControl.Columns>
</grid:RadGridView>

<Button x:Name="btnDelete" Command="{Binding ICDeleteData}" Content="Delete" ></Button>


Thanks,
Gorakhnath Choudhary

1 Answer, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 17 Dec 2009, 03:15 PM
Hi Gorakhnath Choudhary,

 

That is very strange. Unfortunately it is very difficult to determine where the problem is by just looking at the code. Could you please send us a sample application ?


Regards,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Gorakhnath Choudhary
Top achievements
Rank 1
Answers by
Milan
Telerik team
Share this question
or