473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C#-APP: simple DataBinding not so simple

1
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.  
TaxNumberFormatter implements both IFormatProvider and ICustomFormatter, 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 TaxNumberFormatter code in it's full text but can if necessary.

Thanks!

ope
Mar 10 '08 #1
0 1111

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

Similar topics

2
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? ...
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...
0
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...
4
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:...
4
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...
1
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...
7
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...
2
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 ...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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,...
0
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...

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.