Field posting question 
Author Message
 Field posting question

I am having a problem figuring out how to post a field change prior to
running a report. That is, I have a grid on a winform.  I am in a field on
that grid and make a change.  Without moving to another field or another
record I select a Report menu item from the main menu to print a report.
When the report prints the change that I made in the field does not get
reflected in the report.  The report is unaware of the change. This is
apparently because the value in the field is not getting posted to the
dataset.

If, prior to running the report, I move to another record in the grid, the
report shows the change.

How do I solve this problem?



Sun, 27 Nov 2005 01:40:29 GMT  
 Field posting question
This worked for me:

'save any changes to the current grid row by moving off it.

Me.btnReport.Focus()

It was simpler than trying to code the .EndEdit method.
--
Joe Fallon


Quote:
> I am having a problem figuring out how to post a field change prior to
> running a report. That is, I have a grid on a winform.  I am in a field on
> that grid and make a change.  Without moving to another field or another
> record I select a Report menu item from the main menu to print a report.
> When the report prints the change that I made in the field does not get
> reflected in the report.  The report is unaware of the change. This is
> apparently because the value in the field is not getting posted to the
> dataset.

> If, prior to running the report, I move to another record in the grid, the
> report shows the change.

> How do I solve this problem?



Sun, 27 Nov 2005 06:47:26 GMT  
 Field posting question
I also tried this and am satisifed with it because the record is saved by
programmatically moving it down one row whenever the user "leaves" the grid.
i.e. clicks somewhere else.
I was afraid the user would be "stuck" in the grid but testing shows this
works well for my needs.

Private Sub DataGrid2_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid2.Leave

    DataGrid2.CurrentCell = New DataGridCell(DataGrid2.CurrentCell.RowNumber
+ 1, DataGrid2.CurrentCell.ColumnNumber)

End Sub

This is the "right way" to do it but it doesn't work for me because even
though the value is saved, the DataRowState does not change to Modified!
Don't ask me why. It can be frustrating soemtimes.
Private Sub DataGrid2_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid2.Leave

Dim ColumnNumber, RowNumber As Integer

Dim dgc As DataGridColumnStyle

RowNumber = CType(sender, DataGrid).CurrentCell.RowNumber

ColumnNumber= CType(sender, DataGrid).CurrentCell.ColumnNumber

dgc = DataGrid2.TableStyles(0).GridColumnStyles(ColumnNumber)

Me.DataGrid2.EndEdit(dgc, RowNumber, False)

End Sub

--
Joe Fallon


Quote:
> This worked for me:

> 'save any changes to the current grid row by moving off it.

> Me.btnReport.Focus()

> It was simpler than trying to code the .EndEdit method.
> --
> Joe Fallon



> > I am having a problem figuring out how to post a field change prior to
> > running a report. That is, I have a grid on a winform.  I am in a field
on
> > that grid and make a change.  Without moving to another field or another
> > record I select a Report menu item from the main menu to print a report.
> > When the report prints the change that I made in the field does not get
> > reflected in the report.  The report is unaware of the change. This is
> > apparently because the value in the field is not getting posted to the
> > dataset.

> > If, prior to running the report, I move to another record in the grid,
the
> > report shows the change.

> > How do I solve this problem?



Sun, 27 Nov 2005 07:41:34 GMT  
 Field posting question
Thanks for responding.

Quote:
>Me.btnReport.Focus()

Moving to another object or to another row in the Grid (and back) carries
with it some problems of it's own.  When I come back from the Menu I would
like the user to be just where he was when he left.  It would seem that
EndEdit is the way to do it.  I don't know the syntax for doing it on a
field in a grid.  If you or someone else does, I'd kinda like to give that a
try.


Quote:
> This worked for me:

> 'save any changes to the current grid row by moving off it.

> Me.btnReport.Focus()

> It was simpler than trying to code the .EndEdit method.
> --
> Joe Fallon



> > I am having a problem figuring out how to post a field change prior to
> > running a report. That is, I have a grid on a winform.  I am in a field
on
> > that grid and make a change.  Without moving to another field or another
> > record I select a Report menu item from the main menu to print a report.
> > When the report prints the change that I made in the field does not get
> > reflected in the report.  The report is unaware of the change. This is
> > apparently because the value in the field is not getting posted to the
> > dataset.

> > If, prior to running the report, I move to another record in the grid,
the
> > report shows the change.

> > How do I solve this problem?



Sun, 27 Nov 2005 09:00:35 GMT  
 Field posting question
My 2nd example showed one way to use .EndEdit.
But it had its own problems as noted.

What about this idea: move forward 1 row to save and then move back one row
to re-position on same record?

Private Sub DataGrid2_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid2.Leave

    DataGrid2.CurrentCell = New DataGridCell(DataGrid2.CurrentCell.RowNumber
+ 1, DataGrid2.CurrentCell.ColumnNumber)

    DataGrid2.CurrentCell = New DataGridCell(DataGrid2.CurrentCell.RowNumber
- 1, DataGrid2.CurrentCell.ColumnNumber)

End Sub

--
Joe Fallon


Quote:
> Thanks for responding.

> >Me.btnReport.Focus()

> Moving to another object or to another row in the Grid (and back) carries
> with it some problems of it's own.  When I come back from the Menu I would
> like the user to be just where he was when he left.  It would seem that
> EndEdit is the way to do it.  I don't know the syntax for doing it on a
> field in a grid.  If you or someone else does, I'd kinda like to give that
a
> try.



> > This worked for me:

> > 'save any changes to the current grid row by moving off it.

> > Me.btnReport.Focus()

> > It was simpler than trying to code the .EndEdit method.
> > --
> > Joe Fallon



> > > I am having a problem figuring out how to post a field change prior to
> > > running a report. That is, I have a grid on a winform.  I am in a
field
> on
> > > that grid and make a change.  Without moving to another field or
another
> > > record I select a Report menu item from the main menu to print a
report.
> > > When the report prints the change that I made in the field does not
get
> > > reflected in the report.  The report is unaware of the change. This is
> > > apparently because the value in the field is not getting posted to the
> > > dataset.

> > > If, prior to running the report, I move to another record in the grid,
> the
> > > report shows the change.

> > > How do I solve this problem?



Sun, 27 Nov 2005 10:06:04 GMT  
 Field posting question
Hi Woody,

This is because clicking on menu does not change the focus on the form;
therefore, the changes are not committed to the datagrid.  This behavior
makes sense because people might want to click a menu to invoke a command
to manipulate the current focused control, for example the Copy/Cut/Paste
commands.

To workaround this behavior,  you can handle the Click event of the
menuitem and use the code Joe suggested to have the changes committed.

As for the DataGrid.EndEdit method, you can call like this:

DataGridColumnStyle dgc = dataGrid1.TableStyles[0].GridColumnStyles[0];
dataGrid1.EndEdit(dgc,dataGrid1.CurrentCell.RowNumber ,false);

For more information about adding DataGridTableStyle and
DataGridColumnStyles, please refer to:

Adding Tables and Columns to the Windows Forms DataGrid Control
http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskCreatingCusto...
TypesInDataGrid.asp

In addition, you can use the CurrentRowIndex property in the menuitem's
click event:

int intcurrentrow;
intcurrentrow=dataGrid1.CurrentRowIndex;
dataGrid1.CurrentRowIndex=0;
dataGrid1.CurrentRowIndex=intcurrentrow;

Hope this helps.

Regards,

Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------

Quote:
>Subject: Re: Field posting question
>Date: Tue, 10 Jun 2003 18:00:35 -0700
>Lines: 53
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

>Newsgroups: microsoft.public.dotnet.languages.vb
>NNTP-Posting-Host: 168.158-60-66-fuji-dsl.static.surewest.net 66.60.158.168
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:113414
>X-Tomcat-NG: microsoft.public.dotnet.languages.vb

>Thanks for responding.

>>Me.btnReport.Focus()

>Moving to another object or to another row in the Grid (and back) carries
>with it some problems of it's own.  When I come back from the Menu I would
>like the user to be just where he was when he left.  It would seem that
>EndEdit is the way to do it.  I don't know the syntax for doing it on a
>field in a grid.  If you or someone else does, I'd kinda like to give that
a
>try.



>> This worked for me:

>> 'save any changes to the current grid row by moving off it.

>> Me.btnReport.Focus()

>> It was simpler than trying to code the .EndEdit method.
>> --
>> Joe Fallon



>> > I am having a problem figuring out how to post a field change prior to
>> > running a report. That is, I have a grid on a winform.  I am in a field
>on
>> > that grid and make a change.  Without moving to another field or
another
>> > record I select a Report menu item from the main menu to print a
report.
>> > When the report prints the change that I made in the field does not get
>> > reflected in the report.  The report is unaware of the change. This is
>> > apparently because the value in the field is not getting posted to the
>> > dataset.

>> > If, prior to running the report, I move to another record in the grid,
>the
>> > report shows the change.

>> > How do I solve this problem?



Sun, 27 Nov 2005 17:20:17 GMT  
 Field posting question

Quote:
> Me.btnReport.Focus()

I may have underestimated how practical your advice is.  It does solve the
problem and it works.  I have a question though.  I noticed that when I move
focus to another object (like a button) and then move back to the datagrid I
am still in the field where I left off but there is a retangle around the
field, I suppose to indicate that it has focus.  Just so things are exactly
as they were when the user clicked on the menu item, how does one get the
rectangle off the field and back to it's original state?

The thing that is suprising to me, as you pointed out, is that when invoking
an endEdit that the status doesn't change to modified.  I haven't tested
this myself but I assume you are correct.  Seems like a bug to me.  Maybe
Felix will comment.  I suppose, since I already know what field (row) I am
on I could set it to changed explicitely.

I don't mean to make too much out of all of this but what I am doing here
will lay the groundwork for all future applications.  I will do this sort of
thing over and over so I would like to write some logic here once that will
apply in all circumstances.

Thank you for your interest and help.



Mon, 28 Nov 2005 00:08:18 GMT  
 Field posting question
What about this idea: move forward 1 row to save and then move back one row
to re-position on same record?

What if you are on the last record of the grid?  What if there is only one
record in the grid?



Mon, 28 Nov 2005 00:10:31 GMT  
 Field posting question
Felix,
    Thank you for your assist.

Quote:
>clicking on menu does not change the focus on the form.

Yes this does make since.  It would appear that no other event associated
with the grid fires either.  It would be nice if under the circumstances the
leave event would fire because although you do not want to change focus, you
are leaving the grid. If that were the case you could easily put your
posting code there.

But, be that as it may, it seems to me that the real problem here is that
the status of the record does not change to "Changed" when invoking
EndEdit.  I haven't tested this myself but this is what Joe is asserting and
assuming he's right, it does make you wonder why.  Perhaps there is a swtich
that can set to force it to change.  Or, since I know what record I am on I
could set it explicitly.   Any additional thoughts?

Quote:
>In addition, you can use the CurrentRowIndex property in the menuitem's
> click event:

> int intcurrentrow;
> intcurrentrow=dataGrid1.CurrentRowIndex;
> dataGrid1.CurrentRowIndex=0;
> dataGrid1.CurrentRowIndex=intcurrentrow;

I'm sorry, I do not understand what you are getting at by mentioning the
code above.


Mon, 28 Nov 2005 00:25:19 GMT  
 Field posting question
If there is only 1 record and you move forward 1 you move to the New row so
it works.

If you are already on the New Row then I assume it takes you to the next New
row.
(Haven't tried it programmatically, but that is what happens when you do it
manually.)

I see you liked the move of the Focus trick.
That didn't work for me when I had 2 synchronized grids so I came up with
the move a row forward trick.
It is working well for me so far.

I like 1 line of code vs 6 anyway!

The .EndEdit method was a lot of trouble and didn't work because the
RowState didn't change!

Private Sub DataGrid2_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid2.Leave
    Dim ColumnNumber, RowNumber As Integer

    RowNumber = CType(sender, DataGrid).CurrentCell.RowNumber

    ColumnNumber = CType(sender, DataGrid).CurrentCell.ColumnNumber

    Dim dgc As DataGridColumnStyle

    dgc = DataGrid2.TableStyles(0).GridColumnStyles(ColumnNumber)

    Me.DataGrid2.EndEdit(dgc, RowNumber, False)

End Sub

--
Joe Fallon


Quote:
> What about this idea: move forward 1 row to save and then move back one
row
> to re-position on same record?

> What if you are on the last record of the grid?  What if there is only one
> record in the grid?



Mon, 28 Nov 2005 09:07:11 GMT  
 Field posting question
Hi Woody,

Quote:
>But, be that as it may, it seems to me that the real problem here is that
>the status of the record does not change to "Changed" when invoking
>EndEdit.  I haven't tested this myself but this is what Joe is asserting
and
>assuming he's right, it does make you wonder why.  Perhaps there is a
swtich
>that can set to force it to change.  Or, since I know what record I am on I
>could set it explicitly.   Any additional thoughts?

Generally, when you call the EndEdit method, the changes are committed to
the rows and the RowState is set to "Modified", but I am not sure at the
moment why it does not work in this case. I am going to perform further
research on this and update you after this weekend.

As for the following code snippet, I just wanted to tell you that besides
using the CurrentCell property, you can also use the CurrentRowIndex
property to workaround this problem.

Quote:
>> int intcurrentrow;
>> intcurrentrow=dataGrid1.CurrentRowIndex;
>> dataGrid1.CurrentRowIndex=0;
>> dataGrid1.CurrentRowIndex=intcurrentrow;

Thanks,

Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------



Quote:
>Subject: Re: Field posting question
>Date: Wed, 11 Jun 2003 09:25:19 -0700
>Lines: 34
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

>Newsgroups: microsoft.public.dotnet.languages.vb
>NNTP-Posting-Host: 168.158-60-66-fuji-dsl.static.surewest.net 66.60.158.168
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:113598
>X-Tomcat-NG: microsoft.public.dotnet.languages.vb

>Felix,
>    Thank you for your assist.

>>clicking on menu does not change the focus on the form.

>Yes this does make since.  It would appear that no other event associated
>with the grid fires either.  It would be nice if under the circumstances
the
>leave event would fire because although you do not want to change focus,
you
>are leaving the grid. If that were the case you could easily put your
>posting code there.

>But, be that as it may, it seems to me that the real problem here is that
>the status of the record does not change to "Changed" when invoking
>EndEdit.  I haven't tested this myself but this is what Joe is asserting
and
>assuming he's right, it does make you wonder why.  Perhaps there is a
swtich
>that can set to force it to change.  Or, since I know what record I am on I
>could set it explicitly.   Any additional thoughts?

>>In addition, you can use the CurrentRowIndex property in the menuitem's
>> click event:

>> int intcurrentrow;
>> intcurrentrow=dataGrid1.CurrentRowIndex;
>> dataGrid1.CurrentRowIndex=0;
>> dataGrid1.CurrentRowIndex=intcurrentrow;

>I'm sorry, I do not understand what you are getting at by mentioning the
>code above.



Tue, 29 Nov 2005 18:32:25 GMT  
 Field posting question
Hi Woody,

When the focus is lost or CurrentCell is chagned, the datagrid will call
EndEdit to commit the data, please try the following code in the menuitem's
click event and see if it works:

DataGridColumnStyle dgc =
dataGrid1.TableStyles[0].GridColumnStyles[dataGrid1.CurrentCell.ColumnNumber
 ];
dataGrid1.EndEdit(dgc,dataGrid1.CurrentCell.RowNumber ,false);

To use the following code, you need to create a DataGridColumn for every
column in the datagrid.

If this does not work, I am afraid you need to create a custom
DataGridTextBoxColumn class and call the expose the protected Commit()
method, so that you can call it in the menuitem's click event.

Hope this helps.

Regards,

Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------

Quote:
>X-Tomcat-ID: 233018159






Quote:
>MIME-Version: 1.0
>Content-Type: text/plain
>Content-Transfer-Encoding: 7bit

>Organization: Microsoft
>Date: Fri, 13 Jun 2003 10:32:25 GMT
>Subject: Re: Field posting question
>X-Tomcat-NG: microsoft.public.dotnet.languages.vb

>Newsgroups: microsoft.public.dotnet.languages.vb
>Lines: 83        
>Path: cpmsftngxa06.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:114034
>NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122

>Hi Woody,

>>But, be that as it may, it seems to me that the real problem here is that
>>the status of the record does not change to "Changed" when invoking
>>EndEdit.  I haven't tested this myself but this is what Joe is asserting
>and
>>assuming he's right, it does make you wonder why.  Perhaps there is a
>swtich
>>that can set to force it to change.  Or, since I know what record I am on
I
>>could set it explicitly.   Any additional thoughts?

>Generally, when you call the EndEdit method, the changes are committed to
>the rows and the RowState is set to "Modified", but I am not sure at the
>moment why it does not work in this case. I am going to perform further
>research on this and update you after this weekend.

>As for the following code snippet, I just wanted to tell you that besides
>using the CurrentCell property, you can also use the CurrentRowIndex
>property to workaround this problem.

>>> int intcurrentrow;
>>> intcurrentrow=dataGrid1.CurrentRowIndex;
>>> dataGrid1.CurrentRowIndex=0;
>>> dataGrid1.CurrentRowIndex=intcurrentrow;

>Thanks,

>Felix Wu
>=============
>This posting is provided "AS IS" with no warranties, and confers no rights.

>--------------------





>>Subject: Re: Field posting question
>>Date: Wed, 11 Jun 2003 09:25:19 -0700
>>Lines: 34
>>X-Priority: 3
>>X-MSMail-Priority: Normal
>>X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
>>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

>>Newsgroups: microsoft.public.dotnet.languages.vb
>>NNTP-Posting-Host: 168.158-60-66-fuji-dsl.static.surewest.net
66.60.158.168
>>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
>>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:113598
>>X-Tomcat-NG: microsoft.public.dotnet.languages.vb

>>Felix,
>>    Thank you for your assist.

>>>clicking on menu does not change the focus on the form.

>>Yes this does make since.  It would appear that no other event associated
>>with the grid fires either.  It would be nice if under the circumstances
>the
>>leave event would fire because although you do not want to change focus,
>you
>>are leaving the grid. If that were the case you could easily put your
>>posting code there.

>>But, be that as it may, it seems to me that the real problem here is that
>>the status of the record does not change to "Changed" when invoking
>>EndEdit.  I haven't tested this myself but this is what Joe is asserting
>and
>>assuming he's right, it does make you wonder why.  Perhaps there is a
>swtich
>>that can set to force it to change.  Or, since I know what record I am on
I
>>could set it explicitly.   Any additional thoughts?

>>>In addition, you can use the CurrentRowIndex property in the menuitem's
>>> click event:

>>> int intcurrentrow;
>>> intcurrentrow=dataGrid1.CurrentRowIndex;
>>> dataGrid1.CurrentRowIndex=0;
>>> dataGrid1.CurrentRowIndex=intcurrentrow;

>>I'm sorry, I do not understand what you are getting at by mentioning the
>>code above.



Mon, 05 Dec 2005 00:55:44 GMT  
 Field posting question
Felix,

I had posted this earlier. It looks like your code does the same thing.
Were you able to get the RowState to change?
In my one test, it did not so I went for the simpler option which was to
move off the row to the next row.

The .EndEdit method was a lot of trouble and didn't work because the
RowState didn't change!

Private Sub DataGrid2_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid2.Leave
    Dim ColumnNumber, RowNumber As Integer

    RowNumber = CType(sender, DataGrid).CurrentCell.RowNumber

    ColumnNumber = CType(sender, DataGrid).CurrentCell.ColumnNumber

    Dim dgc As DataGridColumnStyle

    dgc = DataGrid2.TableStyles(0).GridColumnStyles(ColumnNumber)

    Me.DataGrid2.EndEdit(dgc, RowNumber, False)

End Sub

--
Joe Fallon



Quote:
> Hi Woody,

> When the focus is lost or CurrentCell is chagned, the datagrid will call
> EndEdit to commit the data, please try the following code in the
menuitem's
> click event and see if it works:

> DataGridColumnStyle dgc =

dataGrid1.TableStyles[0].GridColumnStyles[dataGrid1.CurrentCell.ColumnNumber
Quote:
>  ];
> dataGrid1.EndEdit(dgc,dataGrid1.CurrentCell.RowNumber ,false);

> To use the following code, you need to create a DataGridColumn for every
> column in the datagrid.

> If this does not work, I am afraid you need to create a custom
> DataGridTextBoxColumn class and call the expose the protected Commit()
> method, so that you can call it in the menuitem's click event.

> Hope this helps.

> Regards,

> Felix Wu
> =============
> This posting is provided "AS IS" with no warranties, and confers no
rights.

> --------------------
> >X-Tomcat-ID: 233018159





> >MIME-Version: 1.0
> >Content-Type: text/plain
> >Content-Transfer-Encoding: 7bit

> >Organization: Microsoft
> >Date: Fri, 13 Jun 2003 10:32:25 GMT
> >Subject: Re: Field posting question
> >X-Tomcat-NG: microsoft.public.dotnet.languages.vb

> >Newsgroups: microsoft.public.dotnet.languages.vb
> >Lines: 83
> >Path: cpmsftngxa06.phx.gbl
> >Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:114034
> >NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122

> >Hi Woody,

> >>But, be that as it may, it seems to me that the real problem here is
that
> >>the status of the record does not change to "Changed" when invoking
> >>EndEdit.  I haven't tested this myself but this is what Joe is asserting
> >and
> >>assuming he's right, it does make you wonder why.  Perhaps there is a
> >swtich
> >>that can set to force it to change.  Or, since I know what record I am
on
> I
> >>could set it explicitly.   Any additional thoughts?

> >Generally, when you call the EndEdit method, the changes are committed to
> >the rows and the RowState is set to "Modified", but I am not sure at the
> >moment why it does not work in this case. I am going to perform further
> >research on this and update you after this weekend.

> >As for the following code snippet, I just wanted to tell you that besides
> >using the CurrentCell property, you can also use the CurrentRowIndex
> >property to workaround this problem.

> >>> int intcurrentrow;
> >>> intcurrentrow=dataGrid1.CurrentRowIndex;
> >>> dataGrid1.CurrentRowIndex=0;
> >>> dataGrid1.CurrentRowIndex=intcurrentrow;

> >Thanks,

> >Felix Wu
> >=============
> >This posting is provided "AS IS" with no warranties, and confers no
rights.

> >--------------------





> >>Subject: Re: Field posting question
> >>Date: Wed, 11 Jun 2003 09:25:19 -0700
> >>Lines: 34
> >>X-Priority: 3
> >>X-MSMail-Priority: Normal
> >>X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
> >>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

> >>Newsgroups: microsoft.public.dotnet.languages.vb
> >>NNTP-Posting-Host: 168.158-60-66-fuji-dsl.static.surewest.net
> 66.60.158.168
> >>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
> >>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:113598
> >>X-Tomcat-NG: microsoft.public.dotnet.languages.vb

> >>Felix,
> >>    Thank you for your assist.

> >>>clicking on menu does not change the focus on the form.

> >>Yes this does make since.  It would appear that no other event
associated
> >>with the grid fires either.  It would be nice if under the circumstances
> >the
> >>leave event would fire because although you do not want to change focus,
> >you
> >>are leaving the grid. If that were the case you could easily put your
> >>posting code there.

> >>But, be that as it may, it seems to me that the real problem here is
that
> >>the status of the record does not change to "Changed" when invoking
> >>EndEdit.  I haven't tested this myself but this is what Joe is asserting
> >and
> >>assuming he's right, it does make you wonder why.  Perhaps there is a
> >swtich
> >>that can set to force it to change.  Or, since I know what record I am
on
> I
> >>could set it explicitly.   Any additional thoughts?

> >>>In addition, you can use the CurrentRowIndex property in the menuitem's
> >>> click event:

> >>> int intcurrentrow;
> >>> intcurrentrow=dataGrid1.CurrentRowIndex;
> >>> dataGrid1.CurrentRowIndex=0;
> >>> dataGrid1.CurrentRowIndex=intcurrentrow;

> >>I'm sorry, I do not understand what you are getting at by mentioning the
> >>code above.



Mon, 05 Dec 2005 06:00:40 GMT  
 Field posting question
Hi Joe ,

I think the culprit of the problem is not the RowState.  We can create a
custom DataGridTextBoxColumn, and define a public method, here we call it
"MyCommit", in the public method, we call the base.SetColumnValueAtRow
method and pass the DataGridTextBox.Text to the method, and then call
Invalidate method to redraw the column. Finally, call
DataGridTextBox.Hide() method  to hide the DataGridTextBox box.

Of course, to implement a DataGridTextBoxColumn, many other works is
requried. You can take a look at this sample, it is a good start point I
think:

How can I put a combobox in a column of a datagrid
http://www.syncfusion.com/faq/winforms/search/480.asp

For test purpose, I hacked the sample by inserting a public method to the
DataGridComboBoxColumn class, naming it "MyCommit":

Public Sub MyCommit()
   LeaveComboBox(Me, EventArgs.Empty)
End Sub

Then, add a menu to the Form1 and call MyCommit() method in the the
menuItem's click event:

Private Sub menuItem2_Click(sender As Object, e As System.EventArgs)
   CType(dataGrid1.TableStyles(0).GridColumnStyles(1),
DataGridComboBoxColumn).MyCommit()
End Sub

Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------








| Subject: Re: Field posting question
| Date: Wed, 18 Jun 2003 18:00:40 -0400
| Lines: 193
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165

| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: syr-24-95-163-153.twcny.rr.com 24.95.163.153
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:115044
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Felix,
|
| I had posted this earlier. It looks like your code does the same thing.
| Were you able to get the RowState to change?
| In my one test, it did not so I went for the simpler option which was to
| move off the row to the next row.
|
|
| The .EndEdit method was a lot of trouble and didn't work because the
| RowState didn't change!
|
| Private Sub DataGrid2_Leave(ByVal sender As Object, ByVal e As
| System.EventArgs) Handles DataGrid2.Leave
|     Dim ColumnNumber, RowNumber As Integer
|
|     RowNumber = CType(sender, DataGrid).CurrentCell.RowNumber
|
|     ColumnNumber = CType(sender, DataGrid).CurrentCell.ColumnNumber
|
|     Dim dgc As DataGridColumnStyle
|
|     dgc = DataGrid2.TableStyles(0).GridColumnStyles(ColumnNumber)
|
|     Me.DataGrid2.EndEdit(dgc, RowNumber, False)
|
| End Sub
|
|
|
| --
| Joe Fallon
|
|
|


| > Hi Woody,
| >
| > When the focus is lost or CurrentCell is chagned, the datagrid will call
| > EndEdit to commit the data, please try the following code in the
| menuitem's
| > click event and see if it works:
| >
| > DataGridColumnStyle dgc =
| >
|
dataGrid1.TableStyles[0].GridColumnStyles[dataGrid1.CurrentCell.ColumnNumber
| >  ];
| > dataGrid1.EndEdit(dgc,dataGrid1.CurrentCell.RowNumber ,false);
| >
| > To use the following code, you need to create a DataGridColumn for every
| > column in the datagrid.
| >
| > If this does not work, I am afraid you need to create a custom
| > DataGridTextBoxColumn class and call the expose the protected Commit()
| > method, so that you can call it in the menuitem's click event.
| >
| > Hope this helps.
| >
| > Regards,
| >
| > Felix Wu
| > =============
| > This posting is provided "AS IS" with no warranties, and confers no
| rights.
| >
| >
| > --------------------
| > >X-Tomcat-ID: 233018159





| > >MIME-Version: 1.0
| > >Content-Type: text/plain
| > >Content-Transfer-Encoding: 7bit

| > >Organization: Microsoft
| > >Date: Fri, 13 Jun 2003 10:32:25 GMT
| > >Subject: Re: Field posting question
| > >X-Tomcat-NG: microsoft.public.dotnet.languages.vb

| > >Newsgroups: microsoft.public.dotnet.languages.vb
| > >Lines: 83
| > >Path: cpmsftngxa06.phx.gbl
| > >Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:114034
| > >NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
| > >
| > >Hi Woody,
| > >
| > >>But, be that as it may, it seems to me that the real problem here is
| that
| > >>the status of the record does not change to "Changed" when invoking
| > >>EndEdit.  I haven't tested this myself but this is what Joe is
asserting
| > >and
| > >>assuming he's right, it does make you wonder why.  Perhaps there is a
| > >swtich
| > >>that can set to force it to change.  Or, since I know what record I am
| on
| > I
| > >>could set it explicitly.   Any additional thoughts?
| > >
| > >Generally, when you call the EndEdit method, the changes are committed
to
| > >the rows and the RowState is set to "Modified", but I am not sure at
the
| > >moment why it does not work in this case. I am going to perform further
| > >research on this and update you after this weekend.
| > >
| > >As for the following code snippet, I just wanted to tell you that
besides
| > >using the CurrentCell property, you can also use the CurrentRowIndex
| > >property to workaround this problem.
| > >
| > >>> int intcurrentrow;
| > >>> intcurrentrow=dataGrid1.CurrentRowIndex;
| > >>> dataGrid1.CurrentRowIndex=0;
| > >>> dataGrid1.CurrentRowIndex=intcurrentrow;
| > >
| > >Thanks,
| > >
| > >Felix Wu
| > >=============
| > >This posting is provided "AS IS" with no warranties, and confers no
| rights.
| > >
| > >
| > >--------------------





| > >>Subject: Re: Field posting question
| > >>Date: Wed, 11 Jun 2003 09:25:19 -0700
| > >>Lines: 34
| > >>X-Priority: 3
| > >>X-MSMail-Priority: Normal
| > >>X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > >>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

| > >>Newsgroups: microsoft.public.dotnet.languages.vb
| > >>NNTP-Posting-Host: 168.158-60-66-fuji-dsl.static.surewest.net
| > 66.60.158.168
| > >>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| > >>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:113598
| > >>X-Tomcat-NG: microsoft.public.dotnet.languages.vb
| > >>
| > >>Felix,
| > >>    Thank you for your assist.
| > >>
| > >>>clicking on menu does not change the focus on the form.
| > >>
| > >>Yes this does make since.  It would appear that no other event
| associated
| > >>with the grid fires either.  It would be nice if under the
circumstances
| > >the
| > >>leave event would fire because although you do not want to change
focus,
| > >you
| > >>are leaving the grid. If that were the case you could easily put your
| > >>posting code there.
| > >>
| > >>But, be that as it may, it seems to me that the real problem here is
| that
| > >>the status of the record does not change to "Changed" when invoking
| > >>EndEdit.  I haven't tested this myself but this is what Joe is
asserting
| > >and
| > >>assuming he's right, it does make you wonder why.  Perhaps there is a
| > >swtich
| > >>that can set to force it to change.  Or, since I know what record I am
| on
| > I
| > >>could set it explicitly.   Any additional thoughts?
| > >>
| > >>>In addition, you can use the CurrentRowIndex property in the
menuitem's
| > >>> click event:
| > >>>
| > >>> int intcurrentrow;
| > >>> intcurrentrow=dataGrid1.CurrentRowIndex;
| > >>> dataGrid1.CurrentRowIndex=0;
| > >>> dataGrid1.CurrentRowIndex=intcurrentrow;
| > >>
| > >>I'm sorry, I do not understand what you are getting at by mentioning
the
| > >>code above.
| > >>
| > >>
| > >>
| > >>
| > >>
| > >>
| > >>
| > >
| > >
| >
|
|
|



Tue, 06 Dec 2005 19:29:46 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. FAQ = Frequently Asked Questions - vba - Please read before posting questions - unofficial - March posting

2. FAQ: Frequently Asked Questions - vba - please read before posting questions - unofficial February posting

3. FAQ - Frequently Asked Questions - vba - Please read before posting questions - unofficial - Jan 2003 posting

4. FAQ - frequently asked VBA questions - please read before posting questions - September posting - unofficial

5. FAQ - Frequently Asked Questions (vba) - please read before posting questions - August posting - unofficial

6. FAQ - Frequently Asked Questions - unoffical July posting - please read before posting questions - vba

7. FAQ - Frequently Asked Questions - unofficial June posting - please read before posting questions

8. FAQ - Frequently Asked Questions - unofficial - please read before posting your questions - March posting

9. FAQ - Frequently Asked Questions - unofficial June posting - please read before posting questions

10. FAQ - frequently asked questions - vba - please read before posting - unofficial - June posting

11. FAQ - frequently asked questions - vba - please read before posting - unofficial - May posting

12. FAQ - Frequently asked questions - vba - Please read before posting - unofficial April post

 

 
Powered by phpBB® Forum Software