473,790 Members | 2,561 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C#-APP: simple DataBinding not so simple

1 New Member
I'm monkeying around with databinding, trying to learn all the ins and outs. I'm populating a label from one of my business objects properties which is a string, however, I want some formatting done on the string first. I got this working using the binding's Format event. But, I want to go one step further. Instead of using the Format event, I'm trying to set the FormatString and FormatInfo properties to make the databinding go through the formatter I wrote. The problem is, it's not. It's just assigning the string straight from the BO to the label. Can anyone spot what step I'm missing here?

Expand|Select|Wrap|Line Numbers
  1. Binding taxBinding = new Binding("Text", mCustomer, "TaxNumber");
  2. taxBinding.FormattingEnabled = true;
  3. if (mCustomer.TaxNumberIsSSN)
  4.     taxBinding.FormatString = TaxNumberFormatter.SSN_FORMAT;
  5. else
  6.     taxBinding.FormatString = TaxNumberFormatter.TAX_ID_FORMAT;
  7. taxBinding.FormatInfo = new TaxNumberFormatter();
  8. taxBinding.NullValue = string.Empty;
  9. lblTaxNumber.DataBindings.Add(taxBinding);
  10. //taxBinding.Format += new ConvertEventHandler(TaxNumberFormatter.TaxBinding_Format);
  11.  
TaxNumberFormat ter implements both IFormatProvider and ICustomFormatte r, however, none of the contracted methods are ever called when I put breakpoints on them and this is evident in that my string isn't formatted on the label. This seems so simple yet I can't find what step I'm missing from any online document or my databinding book. Can anyone shed some light on this? If I uncomment the commented line it works fine without all the extra stuff above it, but as I said I'm trying to get a grasp on automatic formatting. Is this normal behavior since no actual conversion needs to take place from my BO.TaxNumber property to the label.Text property? Am I forced to use the Format event because no conversion is taking place?

If you guys need any extra information let me know. I've refrained from showing the TaxNumberFormat ter code in it's full text but can if necessary.

Thanks!

ope
Mar 10 '08 #1
0 1134

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1683
by: Kirk | last post by:
A very simple question for anyone who knows their HTML tags and attributes. Is there an atribute that I can use to hide the white space around a table which I have used to fill an entire page? I have already tried the following which are un-associated with this white space: CellSpacing="0" CellPadding="0"
0
952
by: codymanix | last post by:
I have an Array of strings and want it to be bound to a DataGrid. I hav already set the mappingname of the TableStyle to "Array" and assigned the Array as DataSource. the problem is that the Datagrid dispalys only Garbage: Lenght | ------- | 11 9 3
0
413
by: Robert Ludig | last post by:
How do I bind a textbox to a simple string varaible with databinding? I managed to do the binding but unfortnatedly the textvox does not get updated when I change the string wich the textbox is bound to. I though this automation is on of the purposes of the databinding ... ? What am I doing wrong ? See this little example code: using System;
4
1118
by: Davie | last post by:
How can I bind the following to a comboBox in the compact framework? I'm looking at this example here: http://samples.gotdotnet.com/quickstart/aspplus/default.aspx?url=%2fquickstart%2fwinforms%2fdoc%2fWinFormsData.aspx When I do the following, i just get the application name appearing in the ComboBox. Thanks in advance.
4
1169
by: aroth | last post by:
I have a basic form with some dropdownlist controls that I would like to populate with items from a database. I keep getting the error "Cannot implicitly convert type 'System.Data.SqlClient.SqlDataReader' to 'bugreq.SqlDataReader'". The code from 'codebehind' is posted below. using System; using System.Collections; using System.ComponentModel; using System.Data;
1
857
by: jsubscribe | last post by:
Hello, I have following code in my ASP.NET webform.. <td nowrap align=center><%# DataBinder.Eval(Container, "DataItem.FLAG") %></td> Flag value could be either 'R' or 'P' - if its 'R' I want to print 'Rejected' in font Red and if its 'P' I want to print 'Processed' in greeen.
7
2731
by: Justin Hoffman | last post by:
I am new to vb.net programming and am just exploring the way databinding works with Windows forms and am having trouble with some fairly basic customization of data entry. The form uses the SqlDataAdapter and SqlDataset and loads a very simple table, with both text and integer fields. If a textbox is bound to an integer source where the current value is a valid integer, say 9, I can type in the textbox 'rubbish' and move to another...
2
1126
by: serge calderara | last post by:
Dear all, I have 2 tables from which I create a simple data relation: Table1 has a field name ID which is retrive from a database Table2 has fields ID and Name which is retrived from database I have build a datarelation from Table 1 to Table 2 on field ID, so far so good Base on that my dataset contains following structure :
1
1471
by: jjblt206 | last post by:
Hi, I have a simple nit-picky question. It would be nice for a stringstream to have a member function which returns a C style string (just like a string does) so I could do this, stringstream ss; ss << "Etc..."; ss.c_str() instead of this,
0
9666
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
9512
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,...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9986
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
7530
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
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4094
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
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.