473,715 Members | 5,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help: Need to cause DataGrid row to "flush" contents


I need some help programmaticall y causing a row in a DataGrid to "flush"
its contents to its bound data (in Visual Studio 6 using Windows Forms
with C#).

My issue is I want to send an update to a database from a menu command
while the user is editing a DataGrid. This is unusual in regard to
examples and normal practice in that the cell of the DataGrid still has
the focus. In all examples I can find, the user normally presses a
button on a Form. This practice causes the DataGrid to lose focus and
automatically flush the current row's contents to its bound data member.
But when I attempt to perform an update while the user is STILL editing
data in a row, the DataSet updates WITHOUT that particular row.

I attempted to circumvent this problem by simply setting the focus of
another control on the form (e.g. btnSave.Focus() ), hoping that the
DataGrid would lose focus and flush its row contents to the DataSet, but
this proved to be inexplicably ineffective. The row was still not
flushed. I don't know if a Focus() call needs to iterate once through
the event chain before it finalizes or what.

I really want to do this the right way. I don't want to use a hack like
selecting another row before updating, but I can't find any method in
DataGrid that will force its contents to flush to its bound data. Does
anyone have the definitive procedure on this. Perhaps I'm simply missing
an obvious or well known method here?
Nov 15 '05 #1
11 5944
Junkguy,

I think that the best way to do this would be to call the EndEdit method
on the data grid before you perform the action. This will allow you to end
the current edit and should update the underlying data source when done.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldin o=at=exisconsul ting<dot>com

"Junkguy" <ju*****@columb us.rr.com> wrote in message
news:ju******** *************** ****@news-server-fe-01.columbus.rr. com...

I need some help programmaticall y causing a row in a DataGrid to "flush"
its contents to its bound data (in Visual Studio 6 using Windows Forms
with C#).

My issue is I want to send an update to a database from a menu command
while the user is editing a DataGrid. This is unusual in regard to
examples and normal practice in that the cell of the DataGrid still has
the focus. In all examples I can find, the user normally presses a
button on a Form. This practice causes the DataGrid to lose focus and
automatically flush the current row's contents to its bound data member.
But when I attempt to perform an update while the user is STILL editing
data in a row, the DataSet updates WITHOUT that particular row.

I attempted to circumvent this problem by simply setting the focus of
another control on the form (e.g. btnSave.Focus() ), hoping that the
DataGrid would lose focus and flush its row contents to the DataSet, but
this proved to be inexplicably ineffective. The row was still not
flushed. I don't know if a Focus() call needs to iterate once through
the event chain before it finalizes or what.

I really want to do this the right way. I don't want to use a hack like
selecting another row before updating, but I can't find any method in
DataGrid that will force its contents to flush to its bound data. Does
anyone have the definitive procedure on this. Perhaps I'm simply missing
an obvious or well known method here?

Nov 15 '05 #2
junkguy, what I do is the following:

this.grdWorkshe et.CurrentCell = new DataGridCell(0, 0);
this.grdWorkshe et.CurrentCell = new DataGridCell(0, 1);
this.grdWorkshe et.CurrentCell = new DataGridCell(0, 0);

this way, the focus changes to an existing cell in the datagrid. and
even if the new edited cell is in the same row, the changes will be
updated.

Erald Kulk
Nov 15 '05 #3
In article <Og************ **@TK2MSFTNGP11 .phx.gbl>,
"Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com>
wrote:
I think that the best way to do this would be to call the EndEdit method
on the data grid before you perform the action. This will allow you to end
the current edit and should update the underlying data source when done.

Hope this helps.

Thanks Nicholas,

Wish it would help, but apparently EndEdit is already being called when
AcceptChanges() is called on the data table. I literally tried getting
the CurrencyManager and calling its EndCurrentEdit( ) call. It still
refused to work. As usual, there is some esoteric thing that happens to
really really make the thing end and nobody has caught the bug because
the whateveritiscal l is getting coincidentally invoked by leaving the
DataGrid.

--Junkguy

--
Junkguy
Nov 15 '05 #4
In article <d9************ *************@p osting.google.c om>,
er***@delta-travel.nl (Erald Kulk) wrote:
this.grdWorkshe et.CurrentCell = new DataGridCell(0, 0);
this.grdWorkshe et.CurrentCell = new DataGridCell(0, 1);
this.grdWorkshe et.CurrentCell = new DataGridCell(0, 0);

this way, the focus changes to an existing cell in the datagrid. and
even if the new edited cell is in the same row, the changes will be
updated.


Yeah, that's cool.

I had tried

dg.CurrentCell = new DataGridCell(dg .CurrentRowInde x + 1,0);

This makes it go one row down, which I think is safer because if your
datagrid only contains one column, selecting the second cell won't work-
and in a datagrid that allows edits, there is always "one more row" on
the end. Or if you are on that end row, it does not affect it.

I tried earlier

dg.CurrentRowIn dex += 1;

But that didn't work for some reason, and it throws an exception if you
are on the end row.

The only issue I have found with the "new cell" idea is when the row you
are currently on has a Validation error, the cell you were editing does
not re-highlight. It does re-hilight when you use the mouse to go to the
next row. Weird.

I really want to find out what the exact procedure is. I have actually
been stepping through the disassembled Microsoft code to see what the
heck they are doing. But that is pretty tedious and difficult and I
still haven't figured it out.

<rant>You know, EVERY other window toolkit I have ever used gives you
the code- which of course makes it easy to figure out what they are
doing. Microsoft hides it. I can see hiding the underlying operating
system but come on! The docs are so poor and they use so many esoteric
methodologies it just makes my job that much harder.</rant>

Until I figure out the correct procedures, I guess I'll use the "new
cell" method you describe.

Thanks for your advice.

--
Junkguy
Nov 15 '05 #5
Hi,
dg.CurrentCell = new DataGridCell(dg .CurrentRowInde x + 1,0);
I'd suggest

dg.CurrentCell = new DataGridCell(dg .CurrentCell.Ro wNumber + 1,0);

because CurrentRowIndex is hardwired to the parent table and this approach
won't work for a child table if you bind the grid to a master-detail
dataset.

Unfortunately I cannot access the message that started the thread, could you
please re-post your original problem and I could then probably suggest
something?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Junkguy" <ju*****@columb us.rr.com> wrote in message
news:ju******** *************** ****@news-server-fe-01.columbus.rr. com... In article <d9************ *************@p osting.google.c om>,
er***@delta-travel.nl (Erald Kulk) wrote:
this.grdWorkshe et.CurrentCell = new DataGridCell(0, 0);
this.grdWorkshe et.CurrentCell = new DataGridCell(0, 1);
this.grdWorkshe et.CurrentCell = new DataGridCell(0, 0);

this way, the focus changes to an existing cell in the datagrid. and
even if the new edited cell is in the same row, the changes will be
updated.


Yeah, that's cool.

I had tried

dg.CurrentCell = new DataGridCell(dg .CurrentRowInde x + 1,0);

This makes it go one row down, which I think is safer because if your
datagrid only contains one column, selecting the second cell won't work-
and in a datagrid that allows edits, there is always "one more row" on
the end. Or if you are on that end row, it does not affect it.

I tried earlier

dg.CurrentRowIn dex += 1;

But that didn't work for some reason, and it throws an exception if you
are on the end row.

The only issue I have found with the "new cell" idea is when the row you
are currently on has a Validation error, the cell you were editing does
not re-highlight. It does re-hilight when you use the mouse to go to the
next row. Weird.

I really want to find out what the exact procedure is. I have actually
been stepping through the disassembled Microsoft code to see what the
heck they are doing. But that is pretty tedious and difficult and I
still haven't figured it out.

<rant>You know, EVERY other window toolkit I have ever used gives you
the code- which of course makes it easy to figure out what they are
doing. Microsoft hides it. I can see hiding the underlying operating
system but come on! The docs are so poor and they use so many esoteric
methodologies it just makes my job that much harder.</rant>

Until I figure out the correct procedures, I guess I'll use the "new
cell" method you describe.

Thanks for your advice.

--
Junkguy


Nov 15 '05 #6
Hi,

The CurrencyManager .EndCurrentEdit followed by DataGrid.EndEdi t sequence
works just fine for me. Note that it is a two-step sequence and any of the
steps alone won't do the job. If you follow this sequence and it doesn't
work, could you post a code snippet?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Junkguy" <ju*****@columb us.rr.com> wrote in message
news:ju******** *************** ****@news-server-fe-01.columbus.rr. com...
In article <Og************ **@TK2MSFTNGP11 .phx.gbl>,
"Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com>
wrote:
I think that the best way to do this would be to call the EndEdit method on the data grid before you perform the action. This will allow you to end the current edit and should update the underlying data source when done.

Hope this helps.

Thanks Nicholas,

Wish it would help, but apparently EndEdit is already being called when
AcceptChanges() is called on the data table. I literally tried getting
the CurrencyManager and calling its EndCurrentEdit( ) call. It still
refused to work. As usual, there is some esoteric thing that happens to
really really make the thing end and nobody has caught the bug because
the whateveritiscal l is getting coincidentally invoked by leaving the
DataGrid.

--Junkguy

--
Junkguy


Nov 15 '05 #7
In article <eO************ **@TK2MSFTNGP12 .phx.gbl>,
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.c om> wrote:
The CurrencyManager .EndCurrentEdit followed by DataGrid.EndEdi t sequence
works just fine for me.
Thanks,

The thing that concerned me about this was that somebody else might attempt to
call DataGrid.EndEdi t() because it was automatically invoked (i.e. I didn't
call BeginEdit). DataGrid.EndEdi t() needs a DataGridColumnS tyle, row number,
and a boolean. Who the heck is holding this information while I'm editing a
cell? I would like to get them to do the work. Barring that, I'm a little
unsure as to the best way to get the current DataGridColumnS tyle as DataGrid
does not seem to provide an easy means to it. How do you do get it securely
and then insure that nobody else will make the EndEdit call?

P.S. Here is the original posting I made as per your request:
I need some help programmaticall y causing a row in a DataGrid to "flush"
its contents to its bound data (in Visual Studio 6 using Windows Forms
with C#).

My issue is I want to send an update to a database from a menu command
while the user is editing a DataGrid. This is unusual in regard to
examples and normal practice in that the cell of the DataGrid still has
the focus. In all examples I can find, the user normally presses a
button on a Form. This practice causes the DataGrid to lose focus and
automatically flush the current row's contents to its bound data member.
But when I attempt to perform an update while the user is STILL editing
data in a row, the DataSet updates WITHOUT that particular row.

I attempted to circumvent this problem by simply setting the focus of
another control on the form (e.g. btnSave.Focus() ), hoping that the
DataGrid would lose focus and flush its row contents to the DataSet, but
this proved to be inexplicably ineffective. The row was still not
flushed. I don't know if a Focus() call needs to iterate once through
the event chain before it finalizes or what.

I really want to do this the right way. I don't want to use a hack like
selecting another row before updating, but I can't find any method in
DataGrid that will force its contents to flush to its bound data. Does
anyone have the definitive procedure on this. Perhaps I'm simply missing
an obvious or well known method here?


--
Junkguy
Nov 15 '05 #8
> The thing that concerned me about this was that somebody else might
attempt to
call DataGrid.EndEdi t() because it was automatically invoked (i.e. I didn't call BeginEdit).
No problem with that. To the best of my knowledge, no exception will be
thrown and no bad thing will happen. The method will just return false.
DataGrid.EndEdi t() needs a DataGridColumnS tyle, row number, and a boolean.
Who the heck is holding this information while I'm editing a cell?
The row number can be obtained from dataGrid.Curren tCell.RowNumber .
The boolean just means whether you want to commit changes or roll them back.
The column style is the hardest thing. The only way I know is having column
styles created manually through the TableStyles/GridColumnStyle s collection
designers and then obtaining the corresponding instance by the column
number. The column number is also determined frin the CurrentCell property.

P.S. I am currently finishing work on a DataGrid article that should cover
this issue in particular.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Junkguy" <ju*****@columb us.rr.com> wrote in message
news:ju******** *************** ****@news-server-fe-02.columbus.rr. com... In article <eO************ **@TK2MSFTNGP12 .phx.gbl>,
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.c om> wrote:
The CurrencyManager .EndCurrentEdit followed by DataGrid.EndEdi t sequence
works just fine for me.
Thanks,

The thing that concerned me about this was that somebody else might

attempt to call DataGrid.EndEdi t() because it was automatically invoked (i.e. I didn't call BeginEdit). DataGrid.EndEdi t() needs a DataGridColumnS tyle, row number, and a boolean. Who the heck is holding this information while I'm editing a cell? I would like to get them to do the work. Barring that, I'm a little
unsure as to the best way to get the current DataGridColumnS tyle as DataGrid does not seem to provide an easy means to it. How do you do get it securely and then insure that nobody else will make the EndEdit call?

P.S. Here is the original posting I made as per your request:
I need some help programmaticall y causing a row in a DataGrid to "flush"
its contents to its bound data (in Visual Studio 6 using Windows Forms
with C#).

My issue is I want to send an update to a database from a menu command
while the user is editing a DataGrid. This is unusual in regard to
examples and normal practice in that the cell of the DataGrid still has
the focus. In all examples I can find, the user normally presses a
button on a Form. This practice causes the DataGrid to lose focus and
automatically flush the current row's contents to its bound data member.
But when I attempt to perform an update while the user is STILL editing
data in a row, the DataSet updates WITHOUT that particular row.

I attempted to circumvent this problem by simply setting the focus of
another control on the form (e.g. btnSave.Focus() ), hoping that the
DataGrid would lose focus and flush its row contents to the DataSet, but
this proved to be inexplicably ineffective. The row was still not
flushed. I don't know if a Focus() call needs to iterate once through
the event chain before it finalizes or what.

I really want to do this the right way. I don't want to use a hack like
selecting another row before updating, but I can't find any method in
DataGrid that will force its contents to flush to its bound data. Does
anyone have the definitive procedure on this. Perhaps I'm simply missing
an obvious or well known method here?


--
Junkguy


Nov 15 '05 #9
In article <u1************ **@TK2MSFTNGP12 .phx.gbl>,
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.c om> wrote:
DataGrid.EndEdi t() needs a DataGridColumnS tyle, row number, and a boolean.
Who the heck is holding this information while I'm editing a cell?


Thanks Dmitriy for you response.

We still do not know what called BeginEdit. Some object, somewhere made the
initial call and still holds the info. I think I might just step through the
assembly code and find out.
The row number can be obtained from dataGrid.Curren tCell.RowNumber .
The boolean just means whether you want to commit changes or roll them back.
The column style is the hardest thing. The only way I know is having column
styles created manually through the TableStyles/GridColumnStyle s collection
designers and then obtaining the corresponding instance by the column
number.


Well there's the rub isn't it. Getting the current column style is the most
mind-numbingly difficult thing and it should not be. Committing a row to the
data member should not be like pulling teeth. It should be a common
programmer-accessible call without having to go through hoops.
Anyway, thanks again. I look forward to reading your article.

--
Junkguy
Nov 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2145
by: Jerry | last post by:
Hi All How can I produce an output to the browser and let the script continue to work in the background, producing a later screen output? Example: Trigger a database search so that the user immediately sees a "...searching..." screen while the script actually searches and later on outputs the result.
4
16058
by: Eric West | last post by:
Greetings- I have a web application that has a form that triggers a server process that I would like to provide a "Searching..." page for. My strategy was to send the browser the "top half" of a web page, including an animated "Searching..." gif. I write the contents of this page to the HttpServletResponse output, and then flush the buffer (which I had thought would cause the bytes written thus-far to make their way to the client). I...
8
5476
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
3
29272
by: Jimski | last post by:
Hello all, I am having a problem where I get an error message when I call FlushFinalBlock when decrypting my encrypted text. I am using the Rijndael algorithm. The error message is "Length of the data to decrypt is invalid" and occurs on the csDecrypt.FlushFinalBlock.
7
3704
by: theyas | last post by:
How can I get my code to NOT display two "Open/Save/Cancel/More Info" dialog boxes when using the "Response.WriteFile" method to download a file to IE I've asked about this before and didn't get a satisfactory answer (check your browser) so now that I've had the time to set up a reasonable little test that I can post somewhere, I'll try again. The app I've written has three ASPX pages. One is a combined page which writes a little text...
1
6499
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
3
1573
by: Evan | last post by:
So I have two versions of a program (these are complete programs, not excerpts): Version 1: template <class T > void foo() { return bar( T() ); }
5
2863
by: arnuld | last post by:
this is from mentioned section. i did not understand some things here: it means "flushing the buffer" and "writing to output device" are SAME thing, these are just 2 different names for the same thing. ?
1
3299
by: Sharon | last post by:
Hi, I have a smarty template with about 500 rows, that take a long time to load. I was wondering if there was a way to display it by parts (i.e. first of all display the first 100 rows, then rows 100-200 and so on) Thanks Sharon
0
8823
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8718
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9104
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9047
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5967
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3175
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2119
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.