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

Change the cell content at runtime

7 Answers 644 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alon Ashkenazi
Top achievements
Rank 1
Alon Ashkenazi asked on 18 Nov 2009, 10:41 AM
Hi,
I just started to investigate the gridView control and got stuck in to a problem:
Is it possible to change a specific cell content in a grid view?
I want to with something like this:

radGridView.Rows[radGridView.SelectedRow].Cols["Col_Name"].value =   
MY_NEW_VALUE; 

7 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 18 Nov 2009, 11:22 AM
Hi Alon,

You can change your business object desired property and if your business object implements properly INotifyPropertyChanged this will be refected immediately in the grid. Here is an example:

((YourType)radGridView.SelectedItem).YourProperty =   YourValue;


All the best,
Vlad
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.
0
regis
Top achievements
Rank 1
answered on 27 Nov 2009, 10:16 PM
Hi Vlad,

my gridview is link to a dataset. when I modify manually the value of the cell through the interface everything is fine. But if I modify it by code, nothing change.

I don't know if a dataset implement INotifyPropertyChanged but how can I have the value change by code.
I also try with using beginedit function and commitedit but still not work

.
Thank you
private void gridMain_MouseDoubleClick(object sender, MouseButtonEventArgs e)  
        {  
 
            GridViewCell currentCell = (GridViewCell) gridMain.CurrentCell;  
 
            if (currentCell.DataColumn.DisplayIndex > 17)  
            {  
                  
                if (currentCell.Foreground == Brushes.Red)  
                {  
                    currentCell.Foreground = Brushes.Black;  
                    currentCell.Value = currentCell.Value.ToString().Replace("*""");  
                }  
                else 
                {  
                    currentCell.Foreground = Brushes.Red;  
                    currentCell.Value = currentCell.Value.ToString() + "*";  
                                                             
                      
                }  
      
            }  
              
        } 


0
Vlad
Telerik team
answered on 03 Dec 2009, 08:16 AM
Hello,

The idea is to change desired property of your business object and the grid (cell) will respond immediately. Here is an example:

        private void RadGridView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var dataControl = (GridViewDataControl)sender;
            var currentCell = dataControl.CurrentCell;

            if (currentCell != null)
            {
                ((DataRow)currentCell.DataContext)[currentCell.DataColumn.UniqueName] = 5;
            }
        }

Sincerely yours,
Vlad
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.
0
regis
Top achievements
Rank 1
answered on 04 Dec 2009, 04:47 PM
Hi Vlad,
It's working fine now.
Thank you so much
0
maria
Top achievements
Rank 1
answered on 18 Oct 2018, 08:00 AM

Hi,

I am also facing a similar issue.

I have a grid with 4 columns. On selecting/changing value for 3rd column(i.e.: NewFamily) I want to programmatically set some value for the combobox in 4th column

 

Here is the xaml:

        <telerik:RadGridView Grid.Row="0"  x:Name="PartFamilyGrid" AutoGenerateColumns="False" 
                             ColumnWidth="*" MinHeight="150"
                             RowIndicatorVisibility="Collapsed" SelectionChanged="PartFamilyGrid_SelectionChanged"
                             >  
                <telerik1:StyleManager.Theme>
                    <telerik1:VisualStudio2013Theme/>
                </telerik1:StyleManager.Theme>
                <telerik:RadGridView.Columns>
                
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Family}"    IsReadOnly="True" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Part}"      IsReadOnly="True" />

                <telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <telerik:RadComboBox ItemsSource ="{Binding NewFamily}" SelectionChanged="NewFamilySelected" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                    <telerik:GridViewDataColumn.Header>New Family</telerik:GridViewDataColumn.Header>
                </telerik:GridViewDataColumn>

                <telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <telerik:RadComboBox ItemsSource ="{Binding NewPart}" SelectionChanged="NewPartSelected" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                    <telerik:GridViewDataColumn.Header>New Part</telerik:GridViewDataColumn.Header>
                </telerik:GridViewDataColumn>
                
                
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>

 

Items of this RadGridView are objects of this class

    public class PartFamilyGridItem : INotifyPropertyChanged
        {
        public string Family
            {
            get; set;
            }
        public string Part
            {
            get; set;
            }
        public List<string> NewFamily
            {
            get; set;
            }
        public List<string> NewPart
            {
            get; set;
            }

        public event PropertyChangedEventHandler PropertyChanged;
        }

 

In the SelectionChanged event (NewFamilySelected) for the RadComboBox in 3rd column i want to handle this task. But I am not sure how to do it.

Do I need to get the row of the RadComboBox (from 3rd col) for which value is modified, select the RadComboBox from 4th col and finally change the selectedValue?

0
Dilyan Traykov
Telerik team
answered on 22 Oct 2018, 10:28 AM
Hi maria,

Could you please have a look at the Cascading Combobox Columns demo from our SDK Samples Browser as I believe it demonstrates how to achieve your requirement?

Please let me know if you find it helpful or if you require any further assistance with the implementation. If the latter is the case, may I kindly ask you to open a new support ticket and provide a small sample project demonstrating your current setup?

I look forward to your reply.

Regards,
Dilyan Traykov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
maria
Top achievements
Rank 1
answered on 25 Oct 2018, 07:18 AM

Hi Dilyan Traykov

Thank you. The sample answers my question

Tags
GridView
Asked by
Alon Ashkenazi
Top achievements
Rank 1
Answers by
Vlad
Telerik team
regis
Top achievements
Rank 1
maria
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or