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

Set the content of radgridview Programmatically

3 Answers 637 Views
GridView
This is a migrated thread and some comments may be shown as answers.
payal
Top achievements
Rank 1
payal asked on 19 May 2016, 09:31 AM

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>

3 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 19 May 2016, 05:16 PM
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.
0
payal
Top achievements
Rank 1
answered on 23 May 2016, 09:33 AM

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

0
Martin
Telerik team
answered on 25 May 2016, 08:48 AM
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.
Tags
GridView
Asked by
payal
Top achievements
Rank 1
Answers by
Yoan
Telerik team
payal
Top achievements
Rank 1
Martin
Telerik team
Share this question
or