473,851 Members | 1,961 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);
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.


Mar 10 '08 #1
0 1138

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

Similar topics

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"
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
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;
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.
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;
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.
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...
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 :
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,
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...
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,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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

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.