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

error when use radgridview

1 Answer 81 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nani
Top achievements
Rank 1
Nani asked on 30 Sep 2012, 06:17 PM
I have a form with radgridview bind to bindingsource  and 1 button a 2 textbox also bind to one field from the same bindingSource.

The button when click will add a new row.

When a click the the values from the 2 textbox, keep the values from the last select record from the radgridview.

if i replace the radgridview for the datagridview, the value are cleared, which is the correct behavior, because is a new row with no values assign.

Can any one help me

1 Answer, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 03 Oct 2012, 01:30 PM
Hello Non,

To support this functionality using RadGridView you can call the EndEdit method of the BindingSource component. Here is a sample:
using System;
using System.Data;
using System.Windows.Forms;
 
namespace Lab.Grid
{
    public partial class GridSimpleBindingAddnewForm : Form
    {
 
        private BindingSource bindingSource1 = new BindingSource();
 
        public GridSimpleBindingAddnewForm()
        {
            InitializeComponent();
 
            DataTable table1 = new DataTable();
            table1.Columns.Add("ID");
            table1.Columns.Add("Name");
            table1.Rows.Add(1, "Ivan Petrov");
            table1.Rows.Add(2, "Stefan Muler");
            table1.Rows.Add(3, "Alexandro Ricco");
 
            bindingSource1.DataSource = table1;
 
            radGridView1.DataSource = bindingSource1;
            textBox1.DataBindings.Add("Text", bindingSource1, "Name");
        }
 
        private void radButton1_Click(object sender, EventArgs e)
        {
            bindingSource1.AddNew();
            bindingSource1.EndEdit();
        }
    }
}

I hope this helps.

Regards,
Julian Benkov
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Nani
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Share this question
or