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

Conditionally add empty row

1 Answer 20 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Felice
Top achievements
Rank 1
Felice asked on 03 Jan 2014, 03:37 PM
I will be really glad if I can get some direction on this:
I have a radGridView in a winform in which I have also 4 decimal columns of which 1 (Balance) is calculated with an expression (Balance=Paid-Due+Expenses). All columns are bound to an sql table.
Id-----Date------Due-----Paid-----Expenses-----Balance

How can I generate a new empty row just below the active row if the value of balance is different than 0?
The problems I have are:
-how to get the value contained in "Balance" of the active row
-how to add a row below the active row

Thanks a lot,
Felice
 

1 Answer, 1 is accepted

Sort by
0
Accepted
George
Telerik team
answered on 08 Jan 2014, 11:11 AM
Hello Falice,

Thank you for contacting us.

In order to get the value of the Balance cell in the current row you can use the following code:
object cellValue = this.grid.CurrentRow.Cells["Balance"].Value;
if (cellValue != null)
{
    string valueAsString = cellValue.ToString();
    decimal value = decimal.Parse(valueAsString);
}

And in order to add a row after the current row you can use the Insert method of the Rows collection:
GridViewRowInfo newRow = new GridViewRowInfo(this.grid.MasterView);
this.grid.Rows.Insert(this.grid.CurrentRow.Index + 1, newRow);

I hope this helps.

Regards,
George
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Felice
Top achievements
Rank 1
Answers by
George
Telerik team
Share this question
or