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 

0
mick
2/26/2010 10:21:47 PM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

5 Replies
821 Views

Similar Articles

[PageSpeed] 6

"mick" <coughcough@privacy.com> wrote in message 
news:ubQiWIztKHA.928@TK2MSFTNGP04.phx.gbl...
>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.


Thought tbTotalCost.DataBinding.Add("Text", this,TotalWinnings.ToString());
might work but no. Tried changing the propery ToalCost to a string still 
nothing.
Get - "Cannot bind to the property or column 0 on the DataSource.
Parameter name: dataMember."

This might mean something to someone. Doesnt seem to say why it cant bind
so isnt really much help.

mick 

0
mick
2/26/2010 10:40:32 PM
mick wrote:
> 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);

Is the property you want to bind called "TotalCost"?  Or "TotalWinnings"?

> 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?

No.  It's the other object containing the property to which the "Text" 
property of the "tbTotalCost" is bound.

> Third  should be DataMember.  Erm...

That would be the name of the property in the other object.

Based on the code you posted, perhaps you want something more like this:

   tbTotalCost.DataBinding.Add("Text", this, "TotalWinnings");

Though, typically I'd expect data bindings to be used between two 
different objects, not to bind a property of one object to some other 
property of the same object.

Pete
0
Peter
2/26/2010 10:49:31 PM
"Peter Duniho" <no.peted.spam@no.nwlink.spam.com> wrote in message 
news:ezPy2XztKHA.5384@TK2MSFTNGP04.phx.gbl...
> mick wrote:
>> 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);
>
> Is the property you want to bind called "TotalCost"?  Or "TotalWinnings"?

Oops. There are actually two of them TotalCost and TotalWinnings. Cut and
Pasted the wrong one. Sorry.


>> 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?
>
> No.  It's the other object containing the property to which the "Text" 
> property of the "tbTotalCost" is bound.
>
>> Third  should be DataMember.  Erm...
>
> That would be the name of the property in the other object.
>
> Based on the code you posted, perhaps you want something more like this:
>
>   tbTotalCost.DataBinding.Add("Text", this, "TotalWinnings");

This compiles but doesnt update the TextBox. Is there somethig else I should
be doing?

While I was waiting for an answer I actually tried adding a couple of 
EventsHandlers
and triggering them in the setters. It works but not sure if that is how 
people usually
go about it.

mick


0
mick
2/26/2010 11:24:21 PM
mick wrote:
> [...]
>> Based on the code you posted, perhaps you want something more like this:
>>
>>   tbTotalCost.DataBinding.Add("Text", this, "TotalWinnings");
> 
> This compiles but doesnt update the TextBox. Is there somethig else I 
> should be doing?

It's not really possible to say for sure unless you post a concise but 
complete code example, and explain exactly what you are hoping to 
accomplish with the data binding.

Do note that for data binding to work, the objects involved have to 
comply with one of the various data binding models supported.  The data 
binding docs go into more detail with respect to that.

Pete
0
Peter
2/26/2010 11:41:27 PM
"mick" <coughcough@privacy.com> wrote in message 
news:ubQiWIztKHA.928@TK2MSFTNGP04.phx.gbl...
>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

It's a web screen, right?

Overall, what is your application doing?
User one end..... what is the other?
What goes on inbetween?

It would be more usual for you to have a database or some other data store.
Then some data access layer between your screen and the store.
Maybe involving a web service.
That would present some typed object to the screen for binding.
Binding to properties of the screen doesn't make much sense.
Well, outside of richly interactive WPF applications.

I guess you don't understand how to architect an application and you've 
dived into coding..
You're probably best looking at books which present complete recipes.
Even the most extensive online examples tend to gloss over or trivialise 
things which are important in real world apps.

Hope this is of some help. 

0
Andy
2/27/2010 10:10:24 AM
Reply:

Similar Artilces:

Coding problems with User defined Visible Property
Hi I have a report that my users supply to seavel groups. Some do not require certain fields so these will be hidden by using a checkbox on the relevant form. At the moment, I am using the following in code builder: Me.txt[recordNumber].Visible = Forms![Pdoptions]!chk[recordnumbersvisible] Which isn't doing the job. I've checked all the names and they are correct. This code gives me eaither a syntex error, or an expected end error, but I can find no problem. The code is sitting in the "on format" property of the detail section header, of the report I need this to work in. If...

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. ...

Default text in textboxes
I have done this once but don't remember how. The licensee appears in all new textboxes as a default and it can be prevented from appearing, which I would very much like to know how. Can anyone help me with this? Thanks You can use an API call to get the username: Option Explicit Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Function fOSUserName() As String ' Returns the network login name Dim lngLen As Long, lngX As Long Dim strUserName As String strUserName = String$...

Need help developing a Excel VBA Macro to Vaildate data entered into a textbox
I am collecting data from users in a Excel spreadsheet. To ensure all the required fields are filled out, I have created a userform that loads on opening of the spread sheet. Currently there are three Textboxes a command button writes the data to the sheet and highlights in pink any not filledout. I need a higher level of data vaildation on the two other text boxes. Textbox2 must contain an email address (checking for hyperlinked content is probably the easiest way to vaildate for this) Textbox3 must contain only a 9 digit numerical number Option Explicit Dim y As Long Con...

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...

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 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...

text in textbox...
How do I change the text color in a textbox using VC++6. Thanks, RABMissouri In article <1105758768.117625.54770@f14g2000cwb.googlegroups.com>, rabmissouri@yahoo.com says... > How do I change the text color in a textbox using VC++6. Look up WM_CTLCOLOREDIT and WM_CTLCOLORSTATIC and it should tell you what you need to know. -- Later, Jerry. The universe is a figment of its own imagination. Then use a subclass of the control and use the "reflected" =WM_CTLCOLOR handler. Much cleaner than trying to do it in the parent. joe On Fri, 14 Jan 2005 20:58:52 -0...

Serializing some properties of a UserControl-derived class
I have a class derived from UserControl. I need to serialize an object of this class, but only some properties of it, as not all properties are serializable (some of the properties coming from UserControl are like that). When serializing, how could I ignore all the properties coming from the UserControl class? I know there is XmlIgnoreAttribute, but how could I set it to every property of UserControl, as it is not my class? Thank you very much, Chris Use IXmlSerializable interface to de-/serialize only some props. [http://msdn2.microsoft.com/en-us/library/system.xml.serialization.ixmlseria...

Load a Property Page from a mfc Dll
Hello, I'm trying to load a custom property page from a list of plugins dlls, and i'm doing like that: in my exe: CPropertySheet cSheet(_T("Teste"),this); CMainPage cMain; cSheet.AddPage(&cMain); PPSETPPAGES pSetPagesFunc = (PPSETPPAGES)GetProcAddress(m_pDLLhInstance, SETPPPAGES); if(pSetPagesFunc) { pSetPagesFunc(&cSheet); } cSheet.DoModal(); And in the plugin dll's i'm doing the following: __declspec(dllexport) void SetNewPages(CPropertySheet* rp_psheet) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CDllPage* pcPage=new CDl...

How can I apply the same text box properties to a linked set
I have a book which was imported into publisher from word. First let me compliment the design team on the capabilities of the import for both text and styles. I'm happy with what I have--mostly. Now for the problems. Once I got the appropriate fonts installed (the original came from a different machine) and then re-imported styles from the original document to refresh the fonts, the new publication started to look a lot like the original. However the text boxes came in at a different size than the original. I laid out the new publication with my desired page setup - 1/2 letter book...

Make Userform Caption equal textbox contents
How does one make a Userform title bar caption Equal the contents of Textbox1? Can anyone help? Thanks, Roger You can try Private Sub TextBox1_Change() UserForm1.Caption = TextBox1.Text End Sub or you can use Textbox1_Exit event... -- Jacob "Roger on Excel" wrote: > How does one make a Userform title bar caption Equal the contents of Textbox1? > > Can anyone help? > > Thanks, > > Roger Thanks Jacob - works nicely Roger "Jacob Skaria" wrote: > You can try > > Private Sub TextBox1_Change() ...

Folder properties says there are items in Deleted Items but not th
Hello, I have a client that is over his mailbox limit. I checked his folder size and it says there are many emails in his deleted items but when you click on the folder there is nothing there. He is using Office 2007 SP2 on XP SP3. Thanks are you sure you checked the right folders? which version of Exchange do you use? -- Diane Poremsky [MVP - Outlook] Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Center: http://www.slipstick.com/ Outlook Tips by email: mailto:dailytips-subscribe-request@lists.outlooktips.net EMO - a weekly newslet...

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...

Wizard property sheet questions
I'm implementing a bootstrap program (setup.exe) for a new installer that we're creating. Because of our requirements, we need to handle installation of the program suite's prerequisites prior to launching the actual installer, so we've come up with the idea of implementing some of the UI in the bootstrap program. What we need is to be able to implement a wizard-style property sheet without the welcome or completion pages. (Because we're using C++/MFC 8, we're implementing a mini-installer that would install the C++/MFC DLLs, if necessary, before launching the b...

Property Sheet Cancel to Close
Hello, I have a problem, when in a property sheet i perform the cancel to close operation, then if the user make same changes in the property sheet and then presses the close button the OnApply function is called any way... I want to avoid this because if the user presses the close button is because doesn't want to commit the changes (only if the apply is again pressed). How i distinguish that the user presses the Close or the Apply button in the OnApply function? or is any other way to check this? My main idea is to avoid do the commit thing when the user presses the close butto...

Inventory Changes on Item Property Screen
Is there away to disable the changing of inventory numbers on the Item Propoerties screen. It is way to easy for my employees to make a careless error and inadvertantly change a number. Also, when I copy an item to create a new one, it takes the inventory # of the old item and moves it to the new one, and I need to remember to change it....Can this be disabled? Are you talking about the On Hand Quantity, or the Item Lookup Code? In either case, you can disable the fields using the Security features of RMS. The security features are based on the "Security Level" field in Cas...

How to handle dynamic Array properties in a class module?
Hi all, following Chip's suggestion to convert all my UDT to classes, I got into a stumbling block: how to deal with a dynamic array property? Suppose I have Private pYValues() As Double The Property Get should be trivial: Public Property Get YValues() As Double() YValues = pYValues End Property But how about the Property Let? I should handle the case of unallocated and allocated array, but I cannot test allocation of a dynamic array with Is Nothing. How can I get out of this? Thanks, Best Regards deltaquattro (Sergio Rossi) You can handle it like s...

Hyperlinks and Custom Properties
I desperately need help with this! It is driving me crazy. In Custom Properites, I have a label, "email" in the "value" of the details of Custom Properties I want to enter email address with a hyperlink. So that when a user clicks in the Value of the email (eg. "mailto:emailtome@anywhere.com) it will open email. I am able to do this with a tool tip on the shape. But I am being asked to include it in the value of the Custom Properties. Can this be done? Please can someone please help me with this? Thank you. This was answered the last time you aske...

Property Description of a Linked Table
I have coding that allows me to change a tables description in my database: Public Function ChangeName() Dim db As Database Dim tb As String Set db = CurrentDb tb = db.TableDefs("Address").Properties("Description") tb = Now() db.TableDefs("Address").Properties("Description") = tb End Function But when I try to apply this to a linked table it won't do it at all, why is this? If this is impossible, is there a way to link a table and bring it's properties description from the database it's linked to, to my current database? Try this k...

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...

Form Properties...
What is the for property "Fetch Defaults" under the Data tab? Access 2003 doesn't offer any help for this. Also on the control properties under the Other tab, there are three properties dealing with IME. I am not familiar with IME or these properties. Can someone explain? IME Hold IME Mode IME Sentance Mode Thanks, Devlin Devlin, Place your cursor in any of these property text boxes, and hit F1. That brings up context sensitive Help on that particular property. -- hth Al Campagna . Candia Computer Consulting . Candia, NH USA Microsoft Access MVP http://home.com...

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...

Formatting entries in userform textbox
I'm using a userform for enter dates and times into a worksheet. is there a way of formatting the data as it's input like in an Access form? or is there a way to use an Access form to enter the data into Excel? thanks. I don't use access, but you could validate it when the user is leaving the textbox: Option Explicit Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) If IsDate(Me.TextBox1.Value) Then Me.TextBox1.Value = Format(CDate(Me.TextBox1.Value), "mm/dd/yyyy") Else Cancel = True End If End Sub Or maybe you can present...

select from combobox and show a price in textbox
i want to allow the user to select something from a combo box then once selected i want the price to be displayed in either a text box or a list box! i would use a forms toolabr combo box.Click on tha combo box on the forms toolbar and click on the sheet where you want the box.You can then right click on it and drag the borders to adjust its size or position.Right click on the box again and select fornmat control.You will see the following choices Combo box properties Input range Reference to the range containing the values to display in the drop-down list. Cell link Returns...