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

New row cell value

4 Answers 48 Views
GridView
This is a migrated thread and some comments may be shown as answers.
steve
Top achievements
Rank 1
steve asked on 05 Dec 2010, 10:22 PM
Hi all.

I'm pretty stucked with my RadGridview here. I was wondering, and there will be a simple answer to this one;

When the user adds a new row in the grid, i want to assign a value from code. For example a ticket number or something.
So the first cell's value has to be inserted from code when the users adds a row.
I dont seem to find the code responsible for formatting the cells when the user adds a new row.

Thank you for your time

4 Answers, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 05 Dec 2010, 10:57 PM
Hello steve,

Just try something like this:
void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
{
    if (e.Row is GridViewNewRowInfo)
    {
        e.Row.Cells[0].Value = 123;
    }
}

So basically you are saying that when cell begins edit, if the edited row is the new row, in the first cell set this value, here you can define some custom values.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
steve
Top achievements
Rank 1
answered on 05 Dec 2010, 11:05 PM
Hello.

I'm using VB.NET.

e.row is no valid argument for

RadGridView1_CellBeginEdit(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCellCancelEventArgs)

Greetings
0
steve
Top achievements
Rank 1
answered on 05 Dec 2010, 11:10 PM
Thank you.

Problem solved using this code:

Private Sub RadGridView1_CellBeginEdit(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCellCancelEventArgs) Handles RadGridView1.CellBeginEdit
        If TypeOf RadGridView1.CurrentRow.ViewInfo.CurrentRow Is GridViewNewRowInfo Then
            RadGridView1.CurrentRow.Cells(1).Value = 123
        End If
    End Sub
0
Emanuel Varga
Top achievements
Rank 1
answered on 05 Dec 2010, 11:11 PM
Hello again Steve,

So you are using an older version of telerik controls, ok then , so the simplest alternative can:
RadGridView1.CurrentCell.RowInfo or RadGridView1.CurrentRow

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
Tags
GridView
Asked by
steve
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
steve
Top achievements
Rank 1
Share this question
or