Hi,
I have a grid, with 3 columns. 1 column with amount, one with nothing and one with total.
When i put and X in the column with nothing, I want the value of the total being changed into the value of the amount column. I have tried several events, but I dont quite understand how to do it. Should I use the cellformatting event? Thats the one that brings me closest to the desired solution
Thanks
I have a grid, with 3 columns. 1 column with amount, one with nothing and one with total.
When i put and X in the column with nothing, I want the value of the total being changed into the value of the amount column. I have tried several events, but I dont quite understand how to do it. Should I use the cellformatting event? Thats the one that brings me closest to the desired solution
Thanks
3 Answers, 1 is accepted
0
Hello johan,
I am not sure that I understand your question. However, you can choose one of the following options:
1. You can use column expressions:
2. You can use the CellValueChanged event and change the value conditionally:
3. As you supposed, you can handle the CellFormatting event. However, in this case you will change only the visual element's text. The value in the data source will not be changed:
If this is not the case, please describe with more detail the desired behavior and send me your application. I will be glad to help further.
Regards, Jack
the Telerik team
I am not sure that I understand your question. However, you can choose one of the following options:
1. You can use column expressions:
this
.radGridView1.Columns[
"Value2"
].Expression =
"Value + 2"
;
2. You can use the CellValueChanged event and change the value conditionally:
void
radGridView1_CellValueChanged(
object
sender, GridViewCellEventArgs e)
{
if
(e.Column.Name ==
"Value"
)
{
e.Row.Cells[
"Value2"
].Value = (
int
)e.Value + 2;
}
}
3. As you supposed, you can handle the CellFormatting event. However, in this case you will change only the visual element's text. The value in the data source will not be changed:
void
radGridView1_CellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(e.CellElement.ColumnInfo.Name ==
"Value2"
)
{
object
value = e.CellElement.RowInfo.Cells[
"Value"
].Value;
if
(value !=
null
&& value != DBNull.Value)
{
e.CellElement.Text = ((
int
)value+2).ToString();
}
}
}
If this is not the case, please describe with more detail the desired behavior and send me your application. I will be glad to help further.
Regards, Jack
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
FAHID
commented on 18 May 2018, 04:04 PM
Top achievements
Rank 1
Here i have a gridview containg Services, Rate, ChekBox(if checkBox is Checked it means Service is used Otherwise Services Not used) , Quantity , Amount(Rate * Quantity)
Now I want when i Add Quantity then Amount is Automatically Put in "Amount" Cell.
Please Help me How i do this.
I am using C#
0
Hello, Fahid,
RadGridView supports calculated columns which are suitable for your case. Additional information is available in the following help article: https://docs.telerik.com/devtools/winforms/gridview/columns/calculated-columns-(column-expressions)
Here is a sample code snippet:
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Progress Telerik
RadGridView supports calculated columns which are suitable for your case. Additional information is available in the following help article: https://docs.telerik.com/devtools/winforms/gridview/columns/calculated-columns-(column-expressions)
Here is a sample code snippet:
GridViewDecimalColumn rateColumn =
new
GridViewDecimalColumn(
"Rate"
);
radGridView1.MasterTemplate.Columns.Add(rateColumn);
GridViewDecimalColumn quantity =
new
GridViewDecimalColumn(
"Quantity"
);
radGridView1.MasterTemplate.Columns.Add(quantity);
GridViewDecimalColumn amount =
new
GridViewDecimalColumn(
"Total Amount"
);
amount.Expression =
"Rate * Quantity"
;
radGridView1.MasterTemplate.Columns.Add(amount);
for
(
int
i = 0; i < 5; i++)
{
this
.radGridView1.Rows.Add(i);
}
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which
deliver the business app essential building blocks - a grid component,
data visualization (charts) and form elements.
Dilshod
commented on 28 May 2018, 07:59 PM
Top achievements
Rank 1
Hey guys,
I have similar issue in master-detail Grid. In master grid level calculated field is being refreshed as expected but not in details level. Attached example:
public
partial
class
Form1 : Form
{
public
BindingList<Test> tests {
get
;
set
; }
public
Form1()
{
InitializeComponent();
tests =
new
BindingList<Test>();
tests.Add(
new
Test()
{
A = 5,
B = 4,
DetailsList =
new
BindingList<Test>()
{
new
Test
{
A = 11,
B = 22
}
}
}
);
radGridView1.DataSource = tests;
radGridView1.AutoGenerateHierarchy =
true
;
}
}
public
class
Test : INotifyPropertyChanged
{
private
int
_a;
private
int
_b;
public
int
A
{
get
=> _a;
set
{
_a = value;
Calculate();
OnPropertyChanged(
"A"
);
}
}
public
int
B
{
get
=> _b;
set
{
_b = value;
Calculate();
OnPropertyChanged(
"B"
);
}
}
public
int
C {
get
;
private
set
; }
private
void
Calculate()
{
C = A + B;
}
public
BindingList<Test> DetailsList {
get
;
set
; }
public
event
PropertyChangedEventHandler PropertyChanged;
protected
virtual
void
OnPropertyChanged(
string
propertyName)
{
PropertyChanged?.Invoke(
this
,
new
PropertyChangedEventArgs(propertyName));
}
}
0
Hello, Dilshod,
In order to reflect the changes for the inner levels in RadGridView, you can handle the CellValueChanged event and refresh the relevant template:
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Progress Telerik
In order to reflect the changes for the inner levels in RadGridView, you can handle the CellValueChanged event and refresh the relevant template:
private
void
RadGridView1_CellValueChanged(
object
sender, GridViewCellEventArgs e)
{
if
(e.Row.HierarchyLevel == 1)
{
this
.radGridView1.MasterTemplate.Templates[0].Refresh();
}
}
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which
deliver the business app essential building blocks - a grid component,
data visualization (charts) and form elements.