Using C# and winforms.datagrid control

I have a datagrid that is bound to a dataset and the binding is done
like this:


connection1_admin.Open();


SqlCommand myCommand1 = new SqlCommand("select OrgSystemID, OrgSystem,
OrgSystemDescr from tblOrgsystem",connection1_admin);
adapter1_admin=new SqlDataAdapter();
adapter1_admin.SelectCommand = myCommand1;
ds1_admin = new DataSet("tblOrgsystem");
adapter1_admin.Fill(ds1_admin, "tblOrgsystem");
dg1_admin.SetDataBinding(ds1_admin, "tblOrgsystem");
SizeDataGridColumnsToContent(dg1_admin, -1);


connection1_admin.Closed();


When the user makes changes to the datagrid, shouldn't the dataset
reflect these changes?


frmEditOrgSystem frmEditOrgSystem = new frmEditOrgSystem();
DataGridCell currCell;
currCell = dg1_admin.CurrentCell;
int RowNumber = dg1_admin.CurrentRowIndex;
dg1_admin[RowNumber,1] = str_editsystem1;
dg1_admin[RowNumber,2] = str_editsystem2;


However when I do ds1_admin.HasChanges() I get nothing until.....
I click on a different row of the datagrid, then it finds the changes.


Does anyone have any idea what I'm doing wrong????

RE: Changes to datagrid aren't made to dataset. by JayKudecha

JayKudecha
Thu Aug 17 23:34:04 CDT 2006

Hello rhaazy,

Whenever you change focus from a cell to another or from a row to another,
you better accept the changes from the datagridview to dataset or datatable.
e.g.
ds1_admin.AcceptChanges();

This would save the data in the dataset and later on you can manipulate with
the changed data.

Jay Kudecha.


"rhaazy" wrote:

> Using C# and winforms.datagrid control
>
> I have a datagrid that is bound to a dataset and the binding is done
> like this:
>
>
> connection1_admin.Open();
>
>
> SqlCommand myCommand1 = new SqlCommand("select OrgSystemID, OrgSystem,
> OrgSystemDescr from tblOrgsystem",connection1_admin);
> adapter1_admin=new SqlDataAdapter();
> adapter1_admin.SelectCommand = myCommand1;
> ds1_admin = new DataSet("tblOrgsystem");
> adapter1_admin.Fill(ds1_admin, "tblOrgsystem");
> dg1_admin.SetDataBinding(ds1_admin, "tblOrgsystem");
> SizeDataGridColumnsToContent(dg1_admin, -1);
>
>
> connection1_admin.Closed();
>
>
> When the user makes changes to the datagrid, shouldn't the dataset
> reflect these changes?
>
>
> frmEditOrgSystem frmEditOrgSystem = new frmEditOrgSystem();
> DataGridCell currCell;
> currCell = dg1_admin.CurrentCell;
> int RowNumber = dg1_admin.CurrentRowIndex;
> dg1_admin[RowNumber,1] = str_editsystem1;
> dg1_admin[RowNumber,2] = str_editsystem2;
>
>
> However when I do ds1_admin.HasChanges() I get nothing until.....
> I click on a different row of the datagrid, then it finds the changes.
>
>
> Does anyone have any idea what I'm doing wrong????
>
>

Re: Changes to datagrid aren't made to dataset. by rhaazy

rhaazy
Fri Aug 18 13:14:10 CDT 2006

I have tried this and it does not work. The dataset does not receive
the changes made to the datagrid until I change from one cell or row to
another... I have tried everything, from beginedit()...endedit(),
acceptchanges() update() refresh(), nothing, i can't figure it out...

Jay Kudecha wrote:
> Hello rhaazy,
>
> Whenever you change focus from a cell to another or from a row to another,
> you better accept the changes from the datagridview to dataset or datatable.
> e.g.
> ds1_admin.AcceptChanges();
>
> This would save the data in the dataset and later on you can manipulate with
> the changed data.
>
> Jay Kudecha.
>
>
> "rhaazy" wrote:
>
> > Using C# and winforms.datagrid control
> >
> > I have a datagrid that is bound to a dataset and the binding is done
> > like this:
> >
> >
> > connection1_admin.Open();
> >
> >
> > SqlCommand myCommand1 = new SqlCommand("select OrgSystemID, OrgSystem,
> > OrgSystemDescr from tblOrgsystem",connection1_admin);
> > adapter1_admin=new SqlDataAdapter();
> > adapter1_admin.SelectCommand = myCommand1;
> > ds1_admin = new DataSet("tblOrgsystem");
> > adapter1_admin.Fill(ds1_admin, "tblOrgsystem");
> > dg1_admin.SetDataBinding(ds1_admin, "tblOrgsystem");
> > SizeDataGridColumnsToContent(dg1_admin, -1);
> >
> >
> > connection1_admin.Closed();
> >
> >
> > When the user makes changes to the datagrid, shouldn't the dataset
> > reflect these changes?
> >
> >
> > frmEditOrgSystem frmEditOrgSystem = new frmEditOrgSystem();
> > DataGridCell currCell;
> > currCell = dg1_admin.CurrentCell;
> > int RowNumber = dg1_admin.CurrentRowIndex;
> > dg1_admin[RowNumber,1] = str_editsystem1;
> > dg1_admin[RowNumber,2] = str_editsystem2;
> >
> >
> > However when I do ds1_admin.HasChanges() I get nothing until.....
> > I click on a different row of the datagrid, then it finds the changes.
> >
> >
> > Does anyone have any idea what I'm doing wrong????
> >
> >