PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET DataGrid only sets HasChanges to true if another row is selected

Reply

DataGrid only sets HasChanges to true if another row is selected

 
Thread Tools Rate Thread
Old 04-01-2007, 08:06 PM   #1
John Sitka
Guest
 
Posts: n/a
Default DataGrid only sets HasChanges to true if another row is selected


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




  Reply With Quote
Old 04-01-2007, 11:25 PM   #2
Bart Mermuys
Guest
 
Posts: n/a
Default Re: DataGrid only sets HasChanges to true if another row is selected

Hi,

"John Sitka" <johnsitka@REMOVEhotmail.com> wrote in message
news:etJtGvDMHHA.780@TK2MSFTNGP03.phx.gbl...
> 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
>
>
>
>



  Reply With Quote
Old 05-01-2007, 05:35 AM   #3
Cor Ligthert [MVP]
Guest
 
Posts: n/a
Default Re: DataGrid only sets HasChanges to true if another row is selected

John,

In addition to Bart you can make your life easier by using the position from
the currency manager as Bart has already descibed.

http://www.vb-tips.com/dbpages.aspx...68-4e3f3fedb997

Put as well a DataGridView on your form with as datasource the
datasourcemanager.

You can even remove the buttons if you want,

Cor


  Reply With Quote
Old 05-01-2007, 01:06 PM   #4
John Sitka
Guest
 
Posts: n/a
Default Re: DataGrid only sets HasChanges to true if another row is selected

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" <bmermuys.nospam@hotmail.com> wrote in message news:m1gnh.273447$DW5.5578854@phobos.telenet-ops.be...
> Hi,
>
> "John Sitka" <johnsitka@REMOVEhotmail.com> wrote in message news:etJtGvDMHHA.780@TK2MSFTNGP03.phx.gbl...
>> 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
>>
>>
>>
>>

>
>



  Reply With Quote
Old 05-01-2007, 01:18 PM   #5
John Sitka
Guest
 
Posts: n/a
Default Re: DataGrid only sets HasChanges to true if another row is selected

Thanks Cor,

Nice example.....

(but...oh no not again,)

BindingSource

I'm writing to Net 1.1 framework



"Cor Ligthert [MVP]" <notmyfirstname@planet.nl> wrote in message news:%23D75BsIMHHA.4708@TK2MSFTNGP02.phx.gbl...
> John,
>
> In addition to Bart you can make your life easier by using the position from the currency manager as Bart has already descibed.
>
> http://www.vb-tips.com/dbpages.aspx...68-4e3f3fedb997
>
> Put as well a DataGridView on your form with as datasource the datasourcemanager.
>
> You can even remove the buttons if you want,
>
> Cor
>



  Reply With Quote
Old 05-01-2007, 07:47 PM   #6
Cor Ligthert [MVP]
Guest
 
Posts: n/a
Default Re: DataGrid only sets HasChanges to true if another row is selected

john,

Just one row above it.

We are busy with our site.

http://www.vb-tips.com/dbpages.aspx...88-2e91e5295e7c

Cor

"Cor Ligthert [MVP]" <notmyfirstname@planet.nl> schreef in bericht
news:%23D75BsIMHHA.4708@TK2MSFTNGP02.phx.gbl...
> John,
>
> In addition to Bart you can make your life easier by using the position
> from the currency manager as Bart has already descibed.
>
> http://www.vb-tips.com/dbpages.aspx...68-4e3f3fedb997
>
> Put as well a DataGridView on your form with as datasource the
> datasourcemanager.
>
> You can even remove the buttons if you want,
>
> Cor
>



  Reply With Quote
Old 06-01-2007, 04:52 PM   #7
Bart Mermuys
Guest
 
Posts: n/a
Default Re: DataGrid only sets HasChanges to true if another row is selected

Hi,

"John Sitka" <johnsitka@REMOVEhotmail.com> wrote in message
news:udWNBwMMHHA.4376@TK2MSFTNGP04.phx.gbl...
> 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" <bmermuys.nospam@hotmail.com> wrote in message
> news:m1gnh.273447$DW5.5578854@phobos.telenet-ops.be...
>> Hi,
>>
>> "John Sitka" <johnsitka@REMOVEhotmail.com> wrote in message
>> news:etJtGvDMHHA.780@TK2MSFTNGP03.phx.gbl...
>>> 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
>>>
>>>
>>>
>>>

>>
>>

>
>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off