Set the content of radgridview Programmatically

4 posts, 0 answers
  1. payal
    payal avatar
    8 posts
    Member since:
    May 2016

    Posted 19 May Link to this post

    Dear Admin,

    I want to edit the content of radgridview cell programmatically.

    I am usign below code .Would you please help me with the same. While debugging , the currentcell.Value is updated but it does not show up in Radgridview

           var dataControl = (GridViewDataControl)sender;
           currentCell = dataControl.CurrentCell as GridViewCell;
     
    if (currentCell != null)
                {
                    currentCell.Value = s;// s is the string
                 }
     
    //Radgrid view xaml
     
     <telerik:RadGridView.Columns>
     
                                    <telerik:GridViewDataColumn Header="Expectation Set" DataMemberBinding="{Binding ExpectationSet.Name, Mode=TwoWay}" />
     
     
                </telerik:RadGridView.Columns>

  2. Yoan
    Admin
    Yoan avatar
    1066 posts

    Posted 19 May Link to this post

    Hi,

    Generally, it is not recommended to work directly with visual elements and their properties. This is because of the virtualized nature of RadGridView. When the virtualization of the grid is turned on, its elements (the rows/cells) are created when they should be brought into view and they are also reused on scrolling. The recommended approach is to work with the data item, for example:

    var currentItem = (this.clubsGrid.CurrentCell.ParentRow.Item as Club).Name;
     
                var currentItem2 = (this.clubsGrid.CurrentItem as Club).Name; // you need to set the RadGridView.IsSynchronizedWithCurrentItem = true;

    I hope this helps.

    Regards,
    Yoan
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. payal
    payal avatar
    8 posts
    Member since:
    May 2016

    Posted 23 May in reply to Yoan Link to this post

    Dear Yoan,

    I have a business requirement as follows.

    I need to click on radgridview cell and it will open a dropdown.By using the dropdown, I can change the text of selected cell.So this is my approach

    1.My ViewModel
     public class Phase2bViewModel : INotifyPropertyChanged
        {
            private ObservableCollection<Phase2bModel> _collection = new ObservableCollection<Phase2bModel>();
    {
     public Phase2bViewModel()
                {
                this.getItems = new ObservableCollection<Phase2bModel>();
                this.getItems.Add(new Phase2bModel("Ivan", "AMS",ExpectationSet.AvailableSets[0],ModelSet.ModelSets[0]));
                this.getItems.Add(new Phase2bModel("Stefan","AMS", ExpectationSet.AvailableSets[1], ModelSet.ModelSets[1]));
                this.getItems.Add(new Phase2bModel("Maria", "KMS" , ExpectationSet.AvailableSets[2], ModelSet.ModelSets[0]));
    }
     
      public ObservableCollection<Phase2bModel> getItems
            {
                
             
            get { return _collection; }
                set {
                    if (_collection != value)
                    {
                     OnPropertyChanged("getItems");
                    }
                     
                }
            }
         public event PropertyChangedEventHandler PropertyChanged;
     
            private void OnPropertyChanged(string info)
            {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
    }
     
    //Grid
     <telerik:RadGridView
                  
                 Grid.Row="1"
                SelectionUnit ="cell"
                 
                    SelectionMode="Single"
                    ScrollViewer.VerticalScrollBarVisibility="Auto"
                ScrollViewer.HorizontalScrollBarVisibility="Auto"
                x:Name="Phase2bGridView"
                ItemsSource="{Binding getItems}"
                SelectedItem="{Binding getItems}"
                  IsFilteringAllowed="True"
                FilteringMode="Popup"
                IsReadOnly="false"
                
               AutoGenerateColumns="False"
                    CanUserReorderColumns="False"
                    CanUserFreezeColumns="False"
                    RowIndicatorVisibility="Collapsed" MouseDoubleClick ="Phase2bGridView_MouseDoubleClick" IsSynchronizedWithCurrentItem="True">
       <telerik:RadGridView.Columns>
     
                    <telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}" IsEnabled ="false"/>
                    <telerik:GridViewDataColumn Header="Type" DataMemberBinding="{Binding Type}" IsEnabled ="false"/>
                    <telerik:GridViewDataColumn Header="Expectation Set" DataMemberBinding="{Binding ExpectationSet.Name, Mode=TwoWay}" />
                    <telerik:GridViewDataColumn Header="Model" DataMemberBinding="{Binding ModelSet.Name,Mode=TwoWay}" />
     
                </telerik:RadGridView.Columns>
     
            </telerik:RadGridView>
     
    //updating current cell with the dropdown selected value.I am storing the currentCell when grid is clicked.
     
    var currentItem = (currentCell.ParentRow.Item as Phase2bModel).ExpectationSet.Name;
    // Now I want to update the currentitem witht the value I have selected.Would you please suggest me approach

  5. Martin Vatev
    Admin
    Martin Vatev avatar
    87 posts

    Posted 25 May Link to this post

    Hello Payal,

    If I am not missing something the desired behavior can be achieved with the usage of ComboBox Column. Please take a look at the presented approach and consider how it fits your scenario.
    I hope that this helps.

    Regards,
    Martin Vatev
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top