Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Visual Studio 2010 Textbox

Posted on 2010-11-14
11
Medium Priority
?
1,093 Views
Last Modified: 2013-12-17
Hello,

I have recently switched from Microsoft Access to VS C#.  Needless to say there is a learning curve but well worth the effort.

I have been stuck on two things for several days and hope someone can help me.

Problem 1:  How can I get a currency textbox to display the $ sign with the amount?  I was able to figure out how to do it on a currency cell in a grid but can't for the life of me figure how to do it for a single textbox?

Problem 2:  I have a combo box bound to a table that uses two fields, ItemID and ItemDescription.  ItemDescription is displayed. You select an Item and it will filter the data and show just that one Item.  After the selected record is displayed I would like to set the displaymember to null or blank..

Thanks and any help greatly appreciated.

Gary
0
Comment
Question by:garymcgowan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34131963
Assuming your regional settings are en-US:

    decimal price = 10.50M;
    YourTextBox.Text = price.ToString("C");

Open in new window


For the second you can just reset the index to zero (assuming you have an empty item at the top of your list):

    YourComboBox.SelectedIndex = 0;

Open in new window

0
 

Author Comment

by:garymcgowan
ID: 34132074
Thanks for your prompt reply.  Your solution for the textbox works.  How do I get it to work with a bound textbox?  Sorry I didn't state that in my original question.  Yes, my regional settings are en-US.

Thanks,

Gary
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34132141
How are you doing the binding?
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Author Comment

by:garymcgowan
ID: 34132259
I used the Data Source Configuration Wizard connected to a SQL 2008 database.  From the Data Sources pane I drag and dropped the table that contains several fields, one of which is the one in question.  The name of the field is AdvancedDisposalFee and the control is advancedDisposalFeeTextBox.

I hope I explained this correctly.

Thanks,

Gary
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 0 total points
ID: 34132597
Ok, if you want to use formatting then you are going to have to add the Binding manually.

The code would be something like:

advancedDisposalFeeTextBox.DataBindings.Add(new Binding("Text", yourDataSource, "AdvancedDisposalFee", true, DataSourceUpdateMode.OnPropertyChanged, null, "C"));

Open in new window

0
 

Author Comment

by:garymcgowan
ID: 34132819
Carl,

The following snipit is the final code and it compiles error free but throws a runtime error.  

           advancedDisposalFeeTextBox.DataBindings.Add
            (new Binding("Text", system1Dat_2003_SQLDataSet.tblItem, "AdvancedDisposalFee", true,
            DataSourceUpdateMode.OnPropertyChanged, null, "C"));

The error is:

This causes two bindings in the collection to bind to the same property.

I assume this is because the code generated by VS has to be replaced with the code you gave me.  I will work on finding the VS code.  This will be good training for me digging through the code.

Thanks for your help.

Gary
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34134294
It should be a binding against the textbox. Select the TextBox in the designer then, in the Properties pane, go down to the DataBindings setting. If you expand that you should find an entry against the Text property; just remove that.
0
 

Author Comment

by:garymcgowan
ID: 34141570
Why wasn't the 500 points awarded to Carl Tawn?  Please correct this and give him the points.

Thanks,

Gary
0
 

Author Comment

by:garymcgowan
ID: 34141619
Moderator,

This was my mistake and I want Carl Tawn to be awarded the 500 points.

Thanks for your help,

Gary
0
 

Author Closing Comment

by:garymcgowan
ID: 34179124
Carl,

Thanks! This works great and taught me something I will use many times in the future.

Gary
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question