473,391 Members | 1,674 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,391 software developers and data experts.

Combobox - Format Items

Good Morning,

I have a combobox whose list is bound to DataSet1.Sales Growth
Options.Sales Growth. The data is double and I would like it
displayed as a percentage. I have tried two things:

1. I bound the data using DataSource and DisplayMember and then used
the following code:

Private Sub FormatPercent(ByVal sender As Object, ByVal e As
ConvertEventArgs)
If TypeOf e.Value Is Double Then
e.Value = CType(e.Value, Double).ToString("p")
End If
End Sub

Private Sub CashFlow1Form_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
AddHandler Me.SalesGrowthCombo.DataBindings("Text").Format, AddressOf
Me.FormatNumberWithDecimals

The result is that the first item in the list was formatted correctly,
but
the drop-down list of items when you pressed the arrow wasn't.

2. Then I tried eliminating the DataSource and DisplayMember values
and replacing it with the following:

Private Sub CashFlow1Form_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
Dim SalesGrowthItems As New Binding("Text", DataSet1, "Growth
Rate Options.Growth Rate")
Add Handler SalesGrowthItems.Format, AddressOf Me.FormatPercent

This resulted in only one item in my combobox. This one item was
formatted.

If anybody could give me assistance, I would appreciate it.

Thanks,

Carrie


Expand AllCollapse All
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 21 '05 #1
5 3606
Two solution as I see it.

1: Add a new column in your dataset that contains the formatted text you
want in the combobox. (If you populate the Dataset from SQL, this is very
easy to do)
2: Loop through the rows in the dataset and add them to the combo box
yourself, formatting as you go.

Both are easy to do. If you need more help, just let us know.

Chris

"Carrie" <ca*******@hotmail-dot-com.no-spam.invalid> wrote in message
news:42********@127.0.0.1...
Good Morning,

I have a combobox whose list is bound to DataSet1.Sales Growth
Options.Sales Growth. The data is double and I would like it
displayed as a percentage. I have tried two things:

1. I bound the data using DataSource and DisplayMember and then used
the following code:

Private Sub FormatPercent(ByVal sender As Object, ByVal e As
ConvertEventArgs)
If TypeOf e.Value Is Double Then
e.Value = CType(e.Value, Double).ToString("p")
End If
End Sub

Private Sub CashFlow1Form_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
AddHandler Me.SalesGrowthCombo.DataBindings("Text").Format, AddressOf
Me.FormatNumberWithDecimals

The result is that the first item in the list was formatted correctly,
but
the drop-down list of items when you pressed the arrow wasn't.

2. Then I tried eliminating the DataSource and DisplayMember values
and replacing it with the following:

Private Sub CashFlow1Form_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
Dim SalesGrowthItems As New Binding("Text", DataSet1, "Growth
Rate Options.Growth Rate")
Add Handler SalesGrowthItems.Format, AddressOf Me.FormatPercent

This resulted in only one item in my combobox. This one item was
formatted.

If anybody could give me assistance, I would appreciate it.

Thanks,

Carrie


Expand AllCollapse All
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 21 '05 #2
Carrie,

Good evening,

You need for that the datatable.databinding events

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

I hope this helps,

Cor
Nov 21 '05 #3
Carrie,

My answer was wrong, you can add an extra datacolumn with an expression to
your datatable

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

I hope that this one helps?

Cor
Nov 21 '05 #4
I use the method Chris proposed all the time. As he said it's easy. Give it
a try and let us know the results.

"Carrie" wrote:
Good Morning,

I have a combobox whose list is bound to DataSet1.Sales Growth
Options.Sales Growth. The data is double and I would like it
displayed as a percentage. I have tried two things:

1. I bound the data using DataSource and DisplayMember and then used
the following code:

Private Sub FormatPercent(ByVal sender As Object, ByVal e As
ConvertEventArgs)
If TypeOf e.Value Is Double Then
e.Value = CType(e.Value, Double).ToString("p")
End If
End Sub

Private Sub CashFlow1Form_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
AddHandler Me.SalesGrowthCombo.DataBindings("Text").Format, AddressOf
Me.FormatNumberWithDecimals

The result is that the first item in the list was formatted correctly,
but
the drop-down list of items when you pressed the arrow wasn't.

2. Then I tried eliminating the DataSource and DisplayMember values
and replacing it with the following:

Private Sub CashFlow1Form_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
Dim SalesGrowthItems As New Binding("Text", DataSet1, "Growth
Rate Options.Growth Rate")
Add Handler SalesGrowthItems.Format, AddressOf Me.FormatPercent

This resulted in only one item in my combobox. This one item was
formatted.

If anybody could give me assistance, I would appreciate it.

Thanks,

Carrie


Expand AllCollapse All
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 21 '05 #5
I've used Format and Parse events to even format a picture, so it handles
DBNull values, and displays a predefined "no picture" picture. This is the
most ".net" approach, since .net is an event-oriented platform, and it gets
your code the most clean.
In the Format event, you receive each value, and you format it to display in
the control. In the Parse event, you "un-format" the value to save it to the
database. You only have to transform these values, and don't have to worry
for which rows are shown. This is done by the binding.
I suggest this approach.
Hope this helps.
VBen.

"Carrie" <ca*******@hotmail-dot-com.no-spam.invalid> escribió en el mensaje
news:42********@127.0.0.1...
Good Morning,

I have a combobox whose list is bound to DataSet1.Sales Growth
Options.Sales Growth. The data is double and I would like it
displayed as a percentage. I have tried two things:

1. I bound the data using DataSource and DisplayMember and then used
the following code:

Private Sub FormatPercent(ByVal sender As Object, ByVal e As
ConvertEventArgs)
If TypeOf e.Value Is Double Then
e.Value = CType(e.Value, Double).ToString("p")
End If
End Sub

Private Sub CashFlow1Form_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
AddHandler Me.SalesGrowthCombo.DataBindings("Text").Format, AddressOf
Me.FormatNumberWithDecimals

The result is that the first item in the list was formatted correctly,
but
the drop-down list of items when you pressed the arrow wasn't.

2. Then I tried eliminating the DataSource and DisplayMember values
and replacing it with the following:

Private Sub CashFlow1Form_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
Dim SalesGrowthItems As New Binding("Text", DataSet1, "Growth
Rate Options.Growth Rate")
Add Handler SalesGrowthItems.Format, AddressOf Me.FormatPercent

This resulted in only one item in my combobox. This one item was
formatted.

If anybody could give me assistance, I would appreciate it.

Thanks,

Carrie


Expand AllCollapse All
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 21 '05 #6

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

Similar topics

4
by: Newbee | last post by:
Hola I wanted to kno how to clear the current text that is displayed in my combobox I am filling it with a query which is run against my database I have tried this but it not work ...
0
by: Carrie | last post by:
Good Afternoon, I have a combobox whose list is bound to DataSet1.Sales Growth Options.Sales Growth. The data is double and I would like it displayed as a percentage. I have tried two things:...
2
by: Robert | last post by:
I'm sure this is a fairly basic question, but I've been looking all over the web for days for suggestions on how to do this. I've got a datagrid that's bound to a dataset on my form. It includes...
0
by: Doug | last post by:
This is a repost of an item that I still cannot resolve. I have 3 combo boxes. The first leads to the second to the third. When I have selected a value in the second box, the third box shows...
2
by: pmcguire | last post by:
I have derived a ComboBoxColumnStyle that inherits DataGridColumnStyle. It works fine except for one behavior. If the user selects a new value from the ComboBox's pulldown list on a brand new...
6
by: Sakharam Phapale | last post by:
Hi All, How to fill one ComboBox from other ComboBox control? 1) Only setting the reference does the trick but doesn't show items in control. If you see in immediate window, it shows...
6
by: Matt | last post by:
I'm not entirely sure how to describe this issue. I have a number of ComboBoxes in my application which have their text properties bound to a field in a data set. The items loaded in the ComboBox...
5
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I want to create a customized ComboBox where the methods ComboBox.Items.Add and ComboBox.Items.Insert will behave thusly: -- If the item is not present, add it. -- If the item is present, set the...
4
by: Jerad Rose | last post by:
I'm baffled by this -- is there not a typed object used for ComboBox Items? Best I can tell, all of the methods for ComboBox that accept an Item are of type Object. Why in the world is a...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.