|
BindingSource is an IComponent , the main definition of a component being that it implements IDisposable , - so yes it does have a Dispose method, and this is being correctly invoked by the 'Container ' on the form when it gets disposed.
However, I think I have discovered the problem. The issue is the record that is currently on-screen (so it's a data-input form with text-boxes, combo's etc. - not a data-grid)
When you close the form, the record currently on screen, (which was put into edit mode as soon as the record became current) is not removed from edit-mode.
Turns out, there are CancelEdit() and EndEdit() methods on the BindingSource object itself. I trapped the Form.Closing event, and invoked CancelEdit() on the primary binding source for the form, and it now releases all the locks.
I put in some logic to determine if the current record has pending changes, and call EndEdit() instead to keep the changes.
This even works when the binding source has other data sources hanging off it (i.e. when a property of the current object/record is itself a data-source ('cos its a list), - on some forms in my system this can cause upward of 50 records being locked at one time, which was causing lots of headaches when they weren't unlocking)
I am still a little unsure why you have to explicitly call either EndEdit() or CancelEdit() from the binding source - I would have put clean-up code in the Dispose method if I were writing the class. My best guess is that the Begin-End/Cancel edit semantics are more closely coupled with the DataRow and DataGridView components.
|
|
|
|
|
Simon Bridge wrote: Turns out, there are CancelEdit() and EndEdit() methods on the BindingSource object itself.
Not exactly where one would expect them, but such things happen..
Simon Bridge wrote: this can cause upward of 50 records being locked at one time
..with bigger implications than expected.
Simon Bridge wrote: My best guess is that the Begin-End/Cancel edit semantics are more closely coupled with the DataRow and DataGridView components.
Every "Forms"-controls is in edit-mode as long as it has the input-focus. It would sound more logical that "editing" would end as soon as the control is disposed of.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I would like to implement a functionality similar to jQuery TagIt into C# windows forms. Here is the link for jQuery - http://aehlke.github.com/tag-it/
I am thinking of creating a user control for this functionality.
Any help on how to go about this?
|
|
|
|
|
Hi
I have a MS Access 2003 application with a MSSQL 2008R2 database and need to re-write it. It is used at HQ and 4 remote branches.
What will be the best tool to use?
ASP.NET webforms
ASP.NET MVC
WPF and WCF
Silverlight
Windows Forms
Where do I start
Thanks
Japie
|
|
|
|
|
Jaap Britz wrote: ASP.NET webforms
ASP.NET MVC
WPF and WCF
Silverlight
Windows Forms First ask yourself whether it "should" be a Web-application or a Desktop-application. Then consider the GUI that you have most experience with.
Jaap Britz wrote: Where do I start On MSDN[^]
|
|
|
|
|
Good point
|
|
|
|
|
First of all, don't do this!
Second, much easier and better is to write your application from begining to the end. Use SQL Server instead of MS Access database.
You'll find many examples on CP knowledge base (Articles).
|
|
|
|
|
How to deploy a windows application along with mdf file. Here when i install application in client pc. It should maintain database without sql server. I have mdf file of my database. How can i deploy it. I want to deploy as standalone application. Please some one help me to deploy. Step by Step.
|
|
|
|
|
If you want to deploy a standalone application and database also it would be better to use an embedded database. For example: SQLite or SQL Server Compact Edition. In this case database engine is represented by set of assemblies. So you can easy deploy them and database file with your app.
|
|
|
|
|
I've recently brought an old PPC (PocketPC) 2003 project developed in VS 2003 into VS 2008. This converted project has some issues with it so as an alternative to conversion I created a new project a brought the code and forms from the old project, otherwise identical to the original.
One problem is that I'm running into with both the old original and new projects is that if I change a form in any way and then save a new error is flagged by VS: "Constant cannot be the target of an assignment." The error is the same in every form: code generated by the Windows Form Designer, the line that sets name of the form.
Me.Name = "[formname]"
([formname] depends on the form, is something like frmAvailableMaterial, etc). If I delete this line of code the error disappears but the next the time I change the same form, Windows Form Designer again adds the line Me.Name = "[formname]" and is flagged as an error. So the problem keeps reappearing on forms that I have already "fixed". VS 2008 keeps putting back a line that it flags as an error.
For comparison, I looked at a "clean" VS 2008 project that had no forms imported from a VS 2003 project, only forms created within VS 2008. The VS 2008 forms do not show any code generated by Windows Form Designer within the IDE. This form code isn't directly visible to the developer, only indirectly via the form editor. The VS 2003 forms still have this Windows Form Designer code even when brought into VS 2008. Since VS 2008 is having an issue with this form code, it would be ideal if VS 2008 could convert the VS 2003 form to where it would be fully compatible with VS 2008, to where there would be no real functional difference between an imported VS 2003 form and a form created in VS 2008.
Currently, the only work-around that I can think of would be to create new forms within VS 2008 and copy/paste controls and code and manually rewrite events. I'm certain that this would work with the downside being that this would also be a big investment of time and labor. I would like to see if there is an alternative way that permanently fixes this problem but doesn't require a complete reworking of the project. Does anyone know of a way to accomplish this?
You can probably duplicate this error yourself by importing a PPC VS 2003 project into VS 2008 (perhaps it doesn't even need to be PPC).
|
|
|
|
|
The article at this link will help you move the Windows Form Designer generated code to a separate .Designer.vb file for each form in your project.
I don't think, however, that will solve your problem with initializing me.name . My programs all have code to initialize me.name without an error.
I experimented and found that if my code contained a CONST declaration similar to the following declaration, I get the same error as you do.
CONST name as string="Cause an error"
Because of this, I think you have a variable, Sub or Function (maybe a CONST ) in your code that is called "name". If so, change it to something else like "thename" and see what happens.
|
|
|
|
|
Parent = context.table
child = From t in parent where ...
In properties, the datasource is set to parent as well.
The bindingnavigators.bindingsource are set to child, all controls and datagrids are bound to the child bindingsoure.
Add new will instaniate a new row. It displays in the datagrids; however, it will not save. The primary key field maintains 0. As soon as I sort or call a new query the row is gone. On reload the row is gone.
Is there a problem with a child binding source?
me.validate()
me.parentsource.endedit()
me.child.endedit()
parent.resetcurrentitem()
me.context.submitchanges()
I have tried ending edit in reverse order and not reseting the current item (needed to update the changes, which works correctly for some strange crazy reason). The problem exists solely with saving a new row.
Does it make a difference that there are two binding navigators? Due to space and design, I opted for 2, but I have tried the addnew on the second.
Hmmm ... Ideas? (Asked in VB too. Saw the forms forum after.)
|
|
|
|
|
Actually, I solved this in quite an odd manner. I added a textbox for the primary key that was linked (bound) to the parent datasource. This solved the add new.
Why the child could not aquire a key value is beyond me. I simply hid the textbox by placing it behind another control. Oh, that reminds me. You cannot set the visibility to false and the key still add. Again, another thing that eludes me entirely. What does visibility have to do with it? I could not find any documentation that linked the visible status to the enabled status, but ah well. Problem was solved.
|
|
|
|
|
Hey all, is there a way to detect if ANY control is clicked inside a form? The MouseUp, -Down and so on events can only be set for the form itself, but as far as I have tested i out not for any controls that reside inside it - true? Is there another way? Cheers, Dennis
|
|
|
|
|
Please don't crosspost; pick a forum and stick with it. Most of us read multiple forums, and it scatters the answers over various threads.
Original thread is here[^].
|
|
|
|
|
I feel sorry for this poster. He was told to post here, and he's only done what he was told.
|
|
|
|
|
Yup, I spoke too soon again.
|
|
|
|
|
Dennis Bork wrote: The MouseUp, -Down and so on events can only be set for the form itself, but as far as I have tested i out not for any controls that reside inside it - true? Is there another way?
False, anything that inherits from Control[^]. See Richards'[^] answer for a recursive method that loops all controls, and hook 'em up to a single event-handler. The 'sender' argument would tell you what control was clicked.
|
|
|
|
|
Hello Dennis Bork,
With regards to your question,
http://stackoverflow.com/questions/986529/how-to-detect-if-the-mouse-is-inside-the-whole-form-and-child-controls-in-c
Hope this helps!
Best of Luck!
With Kind Regards,
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 8:33am.
|
|
|
|
|
try this logic...
On Form MouseClick Event
{
if typeof control (at current mouse pointer) not equal to panel, and groupbox and... Then
{
detected that non container contol is clicked
}
else
{
detected that container contol is clicked
}
|
|
|
|
|
Hi,
One other (slightly heavy handed) possibility is to override the Windows Procedure in your form.
You can then intercept all the windows messages it receives, and filter down to the mouse events.
eg:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
}
}
You can get an enum containing all the windows message constants here: [^]
|
|
|
|
|
Hi Friends,
I have an installer developed in Wix. I want to execute one batch command during the upgrade operation. I added one Wix custom action in wxs file. Anybody know to which sequce should i add this for my requirement.
Any help would be really blessing for me.
-Prasanth
|
|
|
|
|
Hello.
I want to add a new record into my database( example: StudetDatabase, if i want to add a new student to database then what do I doing? using data binding.
Thanks so much.
|
|
|
|
|
LearnByHeart wrote: if i want to add a new student to database then what do I doing?
You start a browser and go to MSDN[^]
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|