Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

Control validation problem prevents me from tabbing out of a contr

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Doug Perkes - 28 Sep 2004 19:45 GMT
I am using simple databinding on a small form with only about 10
controls. My problem is that the _second_ time I open the form and
edit a value, I am no longer able to tab or click out of the control
that I just changed the value in.

Here's what I mean:
1. Open the app
2. Open the Details form (form uses databound values for textboxes,
code below)
3. Edit the value in the ItemName textbox
4. Click the OK button to close the form
5. Open the Details form a second time
6. Edit the value in the ItemName textbox

Result --> I am now unable to tab out of the ItemName textbox, click
OK or do anything but close the form.

This appears to be a problem with validation, since I cannot click on any
buttons with CausesValidation = true but I can click on buttons with
CausesValidation = false. However, none of my controls on the form have an
event handler for the Validating event.

This happens consistently throughout my application, on both small
forms and large forms.

I must be doing something incorrectly. Can someone point it out to me?

Here's some code:

MyDataSet.MyRow row = // a valid row from a typed dataset
Inside Form_Load:
BindField(ItemName, "Text", row, "ItemName");

public static void BindField(Control control,
  string propertyName,
  object dataSource,
  string dataMember)
{
  Binding binding =
     control.DataBindings[propertyName];
  if (null != binding)
     control.DataBindings.Remove(binding);
  control.DataBindings.Add(
     propertyName, dataSource, dataMember);
}

Signature

----
Doug Perkes

Sijin Joseph - 29 Sep 2004 09:03 GMT
Hi Doug,

Are you closing the form or just hiding it?..Do you create a new
instance of the form when you show it again?

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> I am using simple databinding on a small form with only about 10
> controls. My problem is that the _second_ time I open the form and
[quoted text clipped - 41 lines]
>       propertyName, dataSource, dataMember);
> }
Doug Perkes - 29 Sep 2004 16:27 GMT
Joseph,

I am closing the form, but the problem was still happenning.

What I finally discovered is that I needed to clear all my databindings in
the Dispose method of the form. Adding the code to clear the bindings in the
Dispose method corrected the problem.

For future reference here's the code I am using. I got if from a MSDN
article title "Field Views on Windows Forms 1.0 and 1.1 Data Binding":

internal static void ClearBindings(Control c)
{
    Binding[] bindings = new Binding[c.DataBindings.Count];
    c.DataBindings.CopyTo(bindings, 0);
    c.DataBindings.Clear();
    foreach (Binding binding in bindings)
    {
        TypeDescriptor.Refresh(binding.DataSource);
    }
    foreach (Control cc in c.Controls)
    {
        ClearBindings(cc);
    }
}

-- doug

> Hi Doug,
>
[quoted text clipped - 50 lines]
> >       propertyName, dataSource, dataMember);
> > }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.