DataGrid only sets HasChanges to true if another row is selected

J

John Sitka

Hi,

I have a datagrid that has as it's datasource a filtered datview of the underlying datatable.
The datagrid is set to read only.
When the row header column is clicked it fills a series of textboxes, datapickers etc positioned
below the datagrid on the same form for ease of editing.
Once edits are complete the save button moves these values back to their respective positions in the
seleceted row of the datagrid, then updates the dataadapter across the underlying datatable.
The changes written to the visible datagrid do not mark themselves as changes unless a mouse click
happens somewhere in the datagrid.

How can I program the datagrid to recognize the changes and communicate them to the underlying
datatable without the click?
I was hoping by setting
dataGrid1.CurrentRowIndex = -1
Which represents a Row change from any possible Selected row would do it, but it dosen't.

Thanks
 
B

Bart Mermuys

Hi,

John Sitka said:
Hi,

I have a datagrid that has as it's datasource a filtered datview of the
underlying datatable.
The datagrid is set to read only.
When the row header column is clicked it fills a series of textboxes,
datapickers etc positioned
below the datagrid on the same form for ease of editing.
Once edits are complete the save button moves these values back to their
respective positions in the
seleceted row of the datagrid, then updates the dataadapter across the
underlying datatable.
The changes written to the visible datagrid do not mark themselves as
changes unless a mouse click
happens somewhere in the datagrid.

Try calling EndCurrentEdit on the CurrencyManager (manages the list binding)
returned from BindingContext to make sure editing has ended before updating
or calling getchanges:

BindingContext[dataGrid1.DataSource,dataGrid1.DataMember].EndCurrentEdit();
dataAdapter.Update( ... );


HTH,
Greetings
 
J

John Sitka

Thanks,
I have use the CurrencyManager successfully in the past and I think I need to re look at how I wrote that code.
That was in much more complicated control (list view and datgrids combined) code with drag and drop add
delete (to trash can), list ranking reordering and stuff but in this case it is much more simple.

Just a filtered grid, to see what you need to see at the moment.
Click on a row header to copy the row values to the editing controls (text, datepickers,comboboxes)
then push those edits back to the grid.
Much like a basic Access form would behave, but with the explict need to click a button to acknowledge
that these are the edits that are intended, rather than direct row editing.

My attempts at utilizing the currency manager seem to be missing the mark, I'll find it soon but believe it or not
for now, this works.

dataGrid1.SelectNextControl(this.uxlblcustno,true,false,false,false);

It is somehow sending an event to select one of the readonly cells in the row I'm working on,
which then lets the bindings to the datagrid know that something has changed.
I can't explain it, especially since uxlblcustno is just any old label on the main form?

Graphically it changes how the dataGrid row selection looks, the row is still highlighted but the
first column is kiind of in some superimpossed editng state.

Anyways, I was hung up on this and it got me over the GUI test stage for a meeting with target audience.
That will help redefine the scope of this project and by then who knows.

Thanks lots.





Bart Mermuys said:
Hi,

John Sitka said:
Hi,

I have a datagrid that has as it's datasource a filtered datview of the underlying datatable.
The datagrid is set to read only.
When the row header column is clicked it fills a series of textboxes, datapickers etc positioned
below the datagrid on the same form for ease of editing.
Once edits are complete the save button moves these values back to their respective positions in the
seleceted row of the datagrid, then updates the dataadapter across the underlying datatable.
The changes written to the visible datagrid do not mark themselves as changes unless a mouse click
happens somewhere in the datagrid.

Try calling EndCurrentEdit on the CurrencyManager (manages the list binding) returned from BindingContext to make sure editing has
ended before updating or calling getchanges:

BindingContext[dataGrid1.DataSource,dataGrid1.DataMember].EndCurrentEdit();
dataAdapter.Update( ... );


HTH,
Greetings

How can I program the datagrid to recognize the changes and communicate them to the underlying
datatable without the click?
I was hoping by setting
dataGrid1.CurrentRowIndex = -1
Which represents a Row change from any possible Selected row would do it, but it dosen't.

Thanks
 
J

John Sitka

Thanks Cor,

Nice example.....

(but...oh no not again,)

BindingSource

I'm writing to Net 1.1 framework
 
B

Bart Mermuys

Hi,

John Sitka said:
Thanks,
I have use the CurrencyManager successfully in the past and I think I need
to re look at how I wrote that code.
That was in much more complicated control (list view and datgrids
combined) code with drag and drop add
delete (to trash can), list ranking reordering and stuff but in this case
it is much more simple.

Just a filtered grid, to see what you need to see at the moment.
Click on a row header to copy the row values to the editing controls
(text, datepickers,comboboxes)
then push those edits back to the grid.
Much like a basic Access form would behave, but with the explict need to
click a button to acknowledge
that these are the edits that are intended, rather than direct row
editing.

Yes i understand that, but even for such a simple case you may need to use a
CurrencyManager mostly for EndCurrentEdit().

A lot of people do have trouble getting the right CurrencyManager. So if
you try, use my exact code.
My attempts at utilizing the currency manager seem to be missing the mark,
I'll find it soon but believe it or not
for now, this works.

dataGrid1.SelectNextControl(this.uxlblcustno,true,false,false,false);

It is somehow sending an event to select one of the readonly cells in the
row I'm working on,
which then lets the bindings to the datagrid know that something has
changed.
I can't explain it, especially since uxlblcustno is just any old label on
the main form?

For me CurrencyManager.EndCurrentEdit() seems to work.

HTH,
Greetings

Graphically it changes how the dataGrid row selection looks, the row is
still highlighted but the
first column is kiind of in some superimpossed editng state.

Anyways, I was hung up on this and it got me over the GUI test stage for a
meeting with target audience.
That will help redefine the scope of this project and by then who knows.

Thanks lots.





Bart Mermuys said:
Hi,

John Sitka said:
Hi,

I have a datagrid that has as it's datasource a filtered datview of the
underlying datatable.
The datagrid is set to read only.
When the row header column is clicked it fills a series of textboxes,
datapickers etc positioned
below the datagrid on the same form for ease of editing.
Once edits are complete the save button moves these values back to their
respective positions in the
seleceted row of the datagrid, then updates the dataadapter across the
underlying datatable.
The changes written to the visible datagrid do not mark themselves as
changes unless a mouse click
happens somewhere in the datagrid.

Try calling EndCurrentEdit on the CurrencyManager (manages the list
binding) returned from BindingContext to make sure editing has ended
before updating or calling getchanges:

BindingContext[dataGrid1.DataSource,dataGrid1.DataMember].EndCurrentEdit();
dataAdapter.Update( ... );


HTH,
Greetings

How can I program the datagrid to recognize the changes and communicate
them to the underlying
datatable without the click?
I was hoping by setting
dataGrid1.CurrentRowIndex = -1
Which represents a Row change from any possible Selected row would do
it, but it dosen't.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top