473,404 Members | 2,213 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,404 software developers and data experts.

Formatting databound values

I have a typed dataset that is on a WinForm and I have labels that have their
text properties bound to fields in a data table. The values are of type
decimal. When I dispaly them in the label, I want to add a currency symbol
and also insert comma's for thousands separators.

Is there anyway to specify the formatting for a label or a field without
breaking the databinding and doing it manually? Or can I specify the
databinding in codde and somehow apply formatting?
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Develop ASP.NET applications easier and in less time:
http://www.atozed.com/IntraWeb/
Nov 22 '05 #1
8 3524
Kudzu,

For that are the binding format events.
Very simple to use when you know them

http://msdn.microsoft.com/library/de...ventsTopic.asp

It seems an empty page however the page format en parse are full
explanations

I hope this helps,

Cor
Nov 22 '05 #2
Kudzu,

For that are the binding format events.
Very simple to use when you know them

http://msdn.microsoft.com/library/de...ventsTopic.asp

It seems an empty page however the page format en parse are full
explanations

I hope this helps,

Cor
Nov 22 '05 #3
"Cor Ligthert" <no************@planet.nl> wrote in
news:eF**************@tk2msftngp13.phx.gbl:
For that are the binding format events.
Very simple to use when you know them


But no way to hook them at design time correct? or more accurately, I was
hoping for something like the grid where you can put a format string in a
property and it uses it.

Code isnt a huge deal - I guess I'll just chalk it up to another shortcoming
of WinForms. I hope MS looks through WinForms better in the future, or
actually tries to use it themselves. Comparing it to VCL (Delphi) makes it
look really weak, and even something VB had back as far as VB3 are missing in
WinForms. :(

Thanks for the link though, will at least work better than manually filling
in the controls (well its actually more code, but a better solution).
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/
Nov 22 '05 #4
"Cor Ligthert" <no************@planet.nl> wrote in
news:eF**************@tk2msftngp13.phx.gbl:
For that are the binding format events.
Very simple to use when you know them


Ive said it before and I'll say it again - they WAY overdid the data
bindings to the point that they are a REAL PITA to use in many cases. If
they want to architect the snot out of things thats fine, but at LEAST
engineer in some shortcuts for the routine stuff (Re my codeproject article
on grids) or this case.. In Delphi or even VB it would be simple - put a
format string on the control, or at worst make a calculated field...
WinForms? No way.. because noone at MS actually uses the WinForms stuff, so
its "Academic".. ok rant off... At least with ADO.NET, ASP.NET and most of
the rest of .NET, people at MS actually use it for something other than
demos.. ;(

Ok this is still way too much code to do something this soddingly simple.
If you say its so simple please show me because I dont want to spend hours
on trial and error.. Here is what Ive tried:

private void DecimalToCurrencyString(object sender, ConvertEventArgs
cevent) {
if (cevent.DesiredType == typeof(string)) {
cevent.Value = ((decimal)cevent.Value).ToString("n2");
}
}

private void lablUnprocessedOrderCount_BindingContextChanged(ob ject
sender, System.EventArgs e) {
((Control)sender).DataBindings[0].Format += new ConvertEventHandler
(DecimalToCurrencyString);
}

It hits the code - but the label now display blank instead of the value.
cevent.value is getting set to a string, and its not blank.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Develop ASP.NET applications easier and in less time:
http://www.atozed.com/IntraWeb/
Nov 22 '05 #5
Kudzu,

I assume(d) that you known(knew) what is on this page?

http://msdn.microsoft.com/library/de...classtopic.asp

Cor
Nov 22 '05 #6
"Cor Ligthert" <no************@planet.nl> wrote in
news:Og*************@TK2MSFTNGP15.phx.gbl:
I assume(d) that you known(knew) what is on this page?


I dont want to set it for a whole thread - so unless Im missing something
really obvious....

I have a typed dataset. I have a label, whose text property is databound to a
decimal in the dataset. I want to apply a specific format only to this field
- in this label. In Delphi, and VB (non WinForms) this is soddignly simple. I
have found not simple, or for that matter even relatively simple nor remotely
obvious way to do this and still keep the data binding. I would love to be
proven wrong on this - but so nearly everytime Ive encoutnered such (re,
curren row in a grid, positioning of records, and more) in Winforms, its
turned out someone got architect happy and never bothered to actually try
their creation in real practice.

Please prove me wrong or confirm my suspcions. :)
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Get your ASP.NET in gear with IntraWeb!
http://www.atozed.com/IntraWeb/
Nov 22 '05 #7
Kudzu,

Does this (old) sample from me fits you, you can make it of course generic,
because you have only to set the event handlers for a type of converting.

This is a slightly more difficult sample than your problem, because it is
about dates and it does both sides.

\\\
Private Sub myroutine()
Mybinding = New Binding("Text", ds.Tables(0), "mydatfield")
textdatfield.DataBindings.Add(Mybinding)
AddHandler mybinding.Format, AddressOf DBdateTextbox
AddHandler mybinding.Parse, AddressOf TextBoxDBdate
End sub
Private Sub DBdateTextbox(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value Is DBNull.Value Then
cevent.Value = ""
Else
Dim datum As Date
datum = CDate(cevent.Value)
cevent.Value = datum.ToString("d")
End If
End Sub
Private Sub TextBoxDBdate(ByVal sender As Object, _
ByVal cevent As ConvertEventArgs)
If cevent.Value.ToString = "" Then
cevent.Value = DBNull.Value
End If
End Sub
///

I hope this helps a little bit?

Cor
Nov 22 '05 #8
"Cor Ligthert" <no************@planet.nl> wrote in
news:Oz**************@TK2MSFTNGP14.phx.gbl:
This is a slightly more difficult sample than your problem, because it
is about dates and it does both sides.


This is essentially what I did, but I didnt declare my binding at run time.
I'll move out of the event into the constructor, maybe it will work there...

Still way way too much code for something simple...
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Empower ASP.NET with IntraWeb
http://www.atozed.com/IntraWeb/
Nov 22 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Chad Z. Hower aka Kudzu | last post by:
I have a typed dataset that is on a WinForm and I have labels that have their text properties bound to fields in a data table. The values are of type decimal. When I dispaly them in the label, I...
1
by: Bruce Vander Werf | last post by:
I need to format a DateTime in the following format: "Mmm dd hh:mm:ss" Where Mmm is the three-letter abbreviation for the month. What's the best way to do this in C#? --Bruce
3
by: Steve Weixel | last post by:
I'm having problems getting dates to format the way that I need them to. The problem is that I'm used to the VB6 way of doing things, with which the statement Format(37866, "dd MMM yyyy") would...
1
by: Johnny Liner | last post by:
Hello... I am creating a CurrencyManager object and setting it like this ... Code: Dim cm as CurrencyManager (...) 'On Open event of form cm = Me.BindingContext(ds,"tblPersonData")
9
by: Vayse | last post by:
I want to make all the databound values locked until the user clicks save. Is there a way doing this, without looping through each control and setting the ReadOnly = True. Thanks Vayse
4
by: jtertin | last post by:
I have a drop-down control that is being populated by an entire table (not a query). There are NULL values in the table which appear as blank spaces in the drop down. How can I format the drop...
1
by: scoarescoare | last post by:
I am running into a problem that I cannot seem to solve. I'm using ADO.NET 2.0 with vb 2005. I have a dataset as a datasource that selects all of the Shoe_Types from a Shoe_Type table. I am...
11
by: irkahs | last post by:
Hello all, I ask this question because I searched and did not find anything that related to this query. My apologies if this is a mistake. Please see the following code. I am using...
2
by: Nathan Sokalski | last post by:
I am using databinding and the Repeater control to display the results of a database query. I normally use the DataBinder.Eval method for this, but in a scenario I am currently dealing with I would...
18
by: maxpirate | last post by:
The currency values are displayed in format of the regional settings specified in the computer of the user. I would like to display all the currency values in dollar format irrespective of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
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,...

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.