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
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.
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() + "*"; |
} |
} |
} |
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.
It's working fine now.
Thank you so much
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?
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
Hi Dilyan Traykov
Thank you. The sample answers my question