Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / June 2007

Tip: Looking for answers? Try searching our database.

DataBinding Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ESmith - 29 Jun 2007 20:49 GMT
I have a schema that defines a STRING variable:  TimeLimit

On my data collection form, there are two numericUpDown controls - one for
hours, one for minutes.
Internally, the program does the conversion, hours * 60 + minutes to get the
TimeLimt in minutes.

Is it possible to DataBind in this situation?  How (can) one create psuedo
field/OnChangedValue update so that when the user enters 1 in hours and 12
in minutes, that that value 72 is bound to the TimeLimit string, and
conversely, the value 72 updates the two numericUpDown controls to 1 and 12
respectively?

TIA!
Morten Wennevik [C# MVP] - 29 Jun 2007 22:19 GMT
> I have a schema that defines a STRING variable:  TimeLimit
>
[quoted text clipped - 10 lines]
>
> TIA!

Hi ESmith,

You can solve this by binding each of the numeric controls to their own property and have those properties update a TimeLimit string/property.  The code below should do what you seek, it will output the calculated time in label1

        protected override void OnLoad(EventArgs e)
        {
            numericUpDown1.DataBindings.Add("Value", this, "Hours", false, DataSourceUpdateMode.OnPropertyChanged);
            numericUpDown2.DataBindings.Add("Value", this, "Minutes", false, DataSourceUpdateMode.OnPropertyChanged);
            label1.DataBindings.Add("Text", this, "Time");
        }

        private int hours;
        private string time;
        private int minutes;

        public int Hours
        {
            get { return hours; }
            set
            {
                hours = value;
                Time = (hours * 60 + Minutes).ToString();
            }
        }

        public int Minutes
        {
            get { return minutes; }
            set
            {
                minutes = value;
                Time = (Hours * 60 + minutes).ToString();
            }
        }

        public string Time
        {
            get { return time; }
            set { time = value; }
        }

Signature

Happy coding!
Morten Wennevik [C# MVP]


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.