Binding and lostfocus

I am using .NET Framework v2. I am binding properties to controls
using complex binding. However until you tab off each control to lose
focus the object being bound to is not updated. To get round this I am
using SendKeys to tab on and off the control. This works fine but you
have to put the sendkeys code in every event handler being bound to
which is horrible. Is there a better way?

Here are some code fragments.

      Protected m_BindingSource As BindingSource = New BindingSource

      UpdateBinding(chkWeek1Month1AtLeaving, "Checked",
m_BindingSource, "Week1Month1IndicatorAtLeaving")

      Protected Sub updateBinding(ByVal c As Control, ByVal prop As
String, ByVal BindingSource As BindingSource, ByVal dataMember As
String)
         If c.DataBindings(prop) IsNot Nothing Then
c.DataBindings.Remove(c.DataBindings(prop))
         c.DataBindings.Add(prop, BindingSource.DataSource,
dataMember)
      End Sub


      Private Sub chkWeek1Month1AtLeaving_CheckedChanged(ByVal sender
As Object, ByVal e As System.EventArgs) Handles
chkWeek1Month1AtLeaving.CheckedChanged
         SendKeys.Send(vbTab + "+" + vbTab)
      End Sub
0
Grim
2/1/2010 11:22:46 AM
dotnet.languages.vb 830 articles. 0 followers. Follow

1 Replies
1349 Views

Similar Articles

[PageSpeed] 31

I have found the answer myself:

      Protected Sub updateBinding(ByVal c As Control, ByVal prop As
String, ByVal BindingSource As BindingSource, ByVal dataMember As
String) ' TODO SLAP IN BASE
         If c.DataBindings(prop) IsNot Nothing Then
c.DataBindings.Remove(c.DataBindings(prop))
         Dim b As Binding = New Binding(prop,
BindingSource.DataSource, dataMember)
         b.DataSourceUpdateMode =
DataSourceUpdateMode.OnPropertyChanged
         c.DataBindings.Add(b)
      End Sub
0
Grim
2/1/2010 11:32:23 AM
Reply:

Similar Artilces:

programmatically change the binding order
All, How can I programmatically change the binding order of the network protocol in Win XP using VC++. Thanks in advance. ...

How do I remove a gutter for a binding edge in Publisher 2007?
I started a document thinking I'd bind it on the left, but as it evolved, I will be binding it on top. I cannot find the place that lets me change this! The print preview, page setup etc. don't give me any options. This is a printer option. Look at your printer setup. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Mayaluga" <Mayaluga@discussions.microsoft.com> wrote in message news:7E8FE3F1-F81A-44D1-BE16-975F3CE7AEF4@microsoft.com... >I started a document thinking I'd bind it on the left, but as ...

Binding a Textbox to a property
I have a property "TotalCost" of type int and a TextBox "tbTotalCost" in the main form "Form1" and was wondering how to bind one to the other tbTotalCost.DataBinding.Add("Text",this.TotalWinnings, erm); First peram. should be Property Name but in the examples Ive seen it usually has "Text". Guessing its because it is the Text property of the TextBox? Second peram. should be object DataSource. That the propery? Third should be DataMember. Erm... Flailing around a bit as you can see. mick "mick" <coughco...

ADP in A2007 Runtime: Traditional binding of form to stored procedure taking no parameters no longer works
Forms in ADP can have a stored procedure as the RecordSource. Traditionally we could write: RecordSource="dbo.EmployeesList" (or use the RecordSourceQualifier to specify "dbo"). On A2007 runtime this no longer works: The record source 'EmployeeList' specified on this form or report does not exist. On A2007 (with or without the /runtime command line switch) it does work. The only workaround I have found so far is to put the entire expression in the RecordSource property like this: "exec dbo.EmployeesList". I don't think this is an intentional change b...

Binding and lostfocus
I am using .NET Framework v2. I am binding properties to controls using complex binding. However until you tab off each control to lose focus the object being bound to is not updated. To get round this I am using SendKeys to tab on and off the control. This works fine but you have to put the sendkeys code in every event handler being bound to which is horrible. Is there a better way? Here are some code fragments. Protected m_BindingSource As BindingSource = New BindingSource UpdateBinding(chkWeek1Month1AtLeaving, "Checked", m_BindingSource, "Week1Month...

socket
CSocket sock; if(sock.Create(0,SOCK_DGRAM,0) == false) { AfxMessageBox("Create"); return; } UINT portnr = 5000; if (sock.Bind(portnr,"10.0.0.10") == false) { int error = sock.GetLastError(); AfxMessageBox("Bind"); return; } When running this code I get an error 10022. According to msdn.microsoft.com it means : 10022 An invalid argument was supplied. WSAEINVAL What am I doing wrong ? Minor detail: it is silly to write "== false" because it might fool you into thinking that the opposite is "== true", which is not always the c...

Attach DatagridView binding into a pop up
Hi all - what would be the cleanest way of showing a databound grid on one screen with a right click "Edit" option that pops up a modal window with databound controls for Editting. I want to preserve the binding that is on the original grid, and apply the updates the minute we hit save. (Editting directly in grids is disallowed by policy for some obscure reason) I was thinking to pass the datasource across into the pop up form - but this aparently causes problems with dropdown boxes forcing records to be marked as "Editted" when no change has actually occu...

Binding XML with attribute to datagrid.
Why is it that when I want to use an attribute like for instance: .WriteAttributeString("WaiterId", "14") and later on (in another application) want to bind the xml to a datagrid with readxml I'm not getting any records (just one row with 14 in it..) If I ommit the attribute it works just fine? What am I doing wrong here, have to admit I'm more or less discovering xml.. Thanks in advance, Mike [Code snippet which writes the XML (Compact Framework)] pXTWWriter = New XmlTextWriter(iFileName, System.Text.Encoding.Default) 'WRITE THE ...

Bindings
My nice new shiny certificate is installed but, as a result of previous efforts to install an incorrect certificate, the SBS Web Applications site and the SharePoint Central Administration v3 site won't start. Attempting to start them fails as "another website may be using the same port". Indeed, when I look at the bindings, I see that the Default Website and the SBS Web Applications sites are both using 80 and 443. I've seen a post from Robbin Meng saying that 443 should not be showing on the Default website but when I try to remove it, I get a fearsome message: &quo...

Binding a option button to a field???
Hi all, Can anyone tell me how to bind a option button to a field in a table? thanks If the option button is part of an option group, you can bind the option group to a Number field in your table. For an example, open the Northwind sample database that installs with Access, and see how the Ship Via option group works on the Orders form. (They use check boxes, but option buttons work the same.) If the option button is not part of a group, you can bind it to a yes/no field in the table. It toggles between two states: chosen and not chosen. Whatever you do, don't create a heap of opti...

Data Binding
Hello, I have a spreadsheet that has 12 tabs, one for each month. I want to move all the raw data to one tab in a database and have another tab reference the data based on which month you choose. <--- This is the easy part. The issue I am having is that when you update the info or add new info how can I bind the data to the database? Access would be so much easier but stuck in excel... Ernst. Generally you define a named range that used a formula, i.e. in the RefersTo box you type something like this: =OFFSET($A$1,0,0,COUNTA($A$1:$A$65536),N) Replace N with the number...

Binding a Graphic
I need to copy 4 rows of text plus a graphic that resides within these four rows. How do I bind the graphic to the cells so that I can copy and paste the aggregate? Select the range of cells that includes the graphic overlay. SHIFT + Edit>Copy Picture. Paste to wherever you wish. Gord Dibben MS Excel MVP On Tue, 17 Nov 2009 14:43:24 -0500, "William Wolfe" <bwolfe@caprock.com> wrote: >I need to copy 4 rows of text plus a graphic that resides within these four >rows. How do I bind the graphic to the cells so that I can copy and paste &...

Binding controls during load event
I am experimenting with binding controls using ADO during the load event. When the form opens I keep getting the parameter query message box. I believe this has something to do with the subform that is linked to the main form. How do you get around this? Works ok as long as form doesn't have subform. If you are merely changing the RecordSource property of the form to a SQL statement, you should be fine, provided fields don't just disappear or change data type (which can cause Access to crash.) However if you are setting the form's Recordset property (Access 2000 and la...

ADP in A2007 Runtime: Traditional binding of form to stored procedure taking no parameters no longer works
Forms in ADP can have a stored procedure as the RecordSource. Traditionally we could write: RecordSource="dbo.EmployeesList" (or use the RecordSourceQualifier to specify "dbo"). On A2007 runtime this no longer works: The record source 'EmployeeList' specified on this form or report does not exist. On A2007 (with or without the /runtime command line switch) it does work. The only workaround I have found so far is to put the entire expression in the RecordSource property like this: "exec dbo.EmployeesList". I don't think this is an intentional change b...

Binding source data source
Hi I have a winform with form controls bound to a binding source. How can I; 1. Use a dynamically created sql to retrieve data from the backend table and use it as data source for binding source? 2. Save the data back to the backend table when data is changed in the form controls and user presses Save on binding navigator? Many Thanks Regards John, The bindingsource is working dynamically. The mistake most often is made, when there are questions like yours, is that persons set a New object to the source of the bindingsource, the source of the bindingsource ...

binding error
how can I fix this binding error I get this runtime error from testing a usercontrol with listbox --------------------------- UserControl TestContainer --------------------------- Failed to create UserControl 'ctlLib.CtlHtmlProc' The error message was 'Complex DataBinding accepts as a data source either an IList or an IListSource.' --------------------------- OK --------------------------- I was binding to dictionary the datasource for the listbox is foreach (enumActn ev in Enum.GetValues(typeof(enumActn))) { string s = Enum.GetName(typeof((enumActn), ev); ...

soap binding
Folks, I need some help. I have a webservice that needs to be consumed by a Java app in Websphere(our customer's partner). Unfortunately, we don't know much on the Java side. The question is that they are requiring that the <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> to include the statement style="document". Any suggestion how I can do this? RJ wrote: > The question is that they are requiring > that the <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> > to include the sta...

Datagridview binding
Datagridview binding is quite simple when using classes that expose fixed attributes using BindingList. Suppose I have a Field that exposes Name and Value attributes. Now, I also have a class Fields which is basically a collection of class Field as you can see: Fields : KeyedCollection<string, Field>. So far everything is fine. But now I want to implement a collection of Fields, which are Rows basically (something like a DataTable) that I can be able to bind easily to a DataGridView. How can I achieve this? TIA ...

EXCEL Keyboard bindings
I am using EXCEL 97 and have encountered a problem with the keyboard binding for the COPY function. Somehow the CTL-C command is not associated to the Copy function. Doing CTL-C actually "centers" the cell. The CTL-C function works fine (COPY) for other MS applications on my PC. Anyone knows where and how I can view the keyboard bindings and change them for EXCEL? Please let me know. When you close Excel and restart does it still happen? If so, if you start Excel in safe mode (Start->Run and enter "Excel.exe /s" without quotes) does it still happen? If no, it...

Late Binding
I have an Access db developed with Access 2003 that will work (with adjustments to references) with 2002 and 2000. Presumeably it will also work with Ofice 2007. So far I've manually adjusted references for each machine I install it on. I'm told that I should look into late binding. I've found some discussions on how to do this with Excel and Outlook. It looks like I change the way I call thse by changing as object to application or vice versa where I call them. I'm pretty sure that I've had to change some of the other references as well and I don't know if...

Plastic comb bindings
As an update I've asked several questions regarding creating a cookbook in Publisher. Now I'd like to ask if anyone has any experience using plastic comb bindings. From what I gather, one chooses the full-sheet size and cuts it to length. Is that accurate? ( I know one must also choose the proper circumference.) http://desktoppub.about.com/cs/binding/qt/coil.htm -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Marsha" <Marsha@discussions.microsoft.com> wrote in message news:375DB43B-7220-4882-8122-59AA1...

Cannot bind a combo box to a memo field
I need to bind a combo box to a field in the database with a memo data type, using to combo box wizard I select the table and I can see all the field in the table except for the one which with a memo data type, why is that? -- Message posted via http://www.accessmonster.com i have found the wizards to be bit unreliable in terms of selecting the fields you really want to use. i have had similar trouble with the crosstab wizard in the past where it would not show certain fields for no particular reason. you can use a memo field for your combo box, just the Row Source propert...

Binding fields from PDF to Access
I am trying to get this to work. Have created a PDF form in LC with data binding to MS Access 07. Connection works fine. Data fields are showing up as choices in LC from access db. Here is the problem. When opening the file in Adobe (acrobat pro), I get a connection failure message: Environment not trusted. But there is no password protection and everything is on the local machine. Help..... I believe this is an Adobe question. Bonnie http://www.dataplus-svc.com Newbie who needs help wrote: >I am trying to get this to work. Have created a PDF form in LC with data ...

margins and gutters for binding
i am trying to format the whole document 80 pages so that i have enough space for the binding holes this is a two sided document so one page needs the space on the left and the next will need it on the right but i cannot see any way of adjusting the entire document or even setting the default text box size before importing the text as when you import a doc from word publisher opens a new file to import to can any one help ? thanks stephen If you do the page setup as a booklet you will have the margin option. Setup 11x17 size paper, landscape. Publisher will ask about adding 3 ...

how to move margin to bind
Hi! I have several years worth of newsletters that I want to have bound. The left margins are too close to the edge to bind without losing some of the text (in the tight binding) Is there a way to smoosh everything to the right a bit to create more space on that left margin? Thanks, and let me know if more info is needed. Jill in Michigan ...