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

Manual CRUD

1 Answer 137 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Felice
Top achievements
Rank 1
Felice asked on 24 Oct 2014, 04:29 AM
I need to use manual crud in my context.

How do I get the values of the cells in the row being update.

private void radGridView1_CellEndEdit(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
        {
            //TextBox t1 = RadGridView1.MasterGridViewInfo.CurrentRow.Cells("Company").Value.ToString();
            //TextBox t2 = RadGridView1.MasterGridViewInfo.CurrentRow.Cells("something").Value.ToString
 
             
             
             {
                 using (var cn = new SqlConnection(connString))
                 {
                     cn.Open();
                     try
                     {
                         SqlCommand cmd = new SqlCommand("UPDATE myTable SET Column = @Parm1 WHERE Col = @Parm2", cn);
                         var parm1 = cmd.CreateParameter("Parm1");
                         parm1.Value = t1.Text;
                         var parm2 = cmd.CreateParameter("Parm2");
                         parm2.Value = t2.text;;
                         cmd.Parameters.Add(parm1);
                         cmd.Parameters.Add(parm2);
                         int rowsAffected = cmd.ExecuteNonQuery();
                     }
                     catch (SqlException ex)
                     {
                         //MessageBox.Show(ex.StackTrace);
                     }
                 }
             
             }
        }

1) The first two lines of code above is what I use to implement in radgrid for asp. How do I get those values in this context winforms?
2) I also have added a delete button column. I do I code the event to delete the row where the button is clicked?

Thanks

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 28 Oct 2014, 02:59 PM
Hello Felice,

Thank you for writing.

1. Pproper events for tracking changes in RadGridView are CellValueChanged and RowsChanged events. You can retrieve the values in this events very easy:
void radGridView1_RowsChanged(object sender, Telerik.WinControls.UI.GridViewCollectionChangedEventArgs e)
{
    GridViewRowInfo row = e.NewItems[0] as GridViewRowInfo;
    string value1 = (string)row.Cells["Name"].Value;
}
 
void radGridView1_CellValueChanged(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
    string value1 = (string)e.Row.Cells["Name"].Value;
    var curentChangedValue = e.Value;
}

You can retrieve the values in the CellEndEdit event as well, but this event will fire even if no changes are made:
void radGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
{
    string value1 = (string)e.Row.Cells[e.Column.Name].Value;
    string value2 = (string)e.Row.Cells["Name"].Value;
}

2. You can use the CommandCellClick event of the grid and delete the row there:
void radGridView1_CommandCellClick(object sender, EventArgs e)
{
    radGridView1.Rows.Remove(radGridView1.CurrentRow);
}

Please let me know if there is something else I can help you with. 

Regards,
Dimitar
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Felice
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or