Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Binding a combobox to a business object with an arraylis
Message
From
06/03/2005 12:05:12
 
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
OS:
Windows XP SP2
Miscellaneous
Thread ID:
00992995
Message ID:
00993108
Views:
21
John,

Well, that new DataConnector class doesn't seem to buy you anything, at least not the way you're using it in this example ... I guess maybe I should find somewhere to read up on it to see what the "benefits" of using it are supposed to be.

~~Bonnie


>Bonnie,
>
>I've now got it working with a DataConnector (but what a hassle to get round)
>
>The code goes something like
>
#region Using directives
>using System;
>using System.Collections;
>using System.ComponentModel;
>using System.Data;
>using System.Drawing;
>using System.Windows.Forms;
>
>#endregion
>
>namespace JTB.TimeRecorder
>{
>    partial class StartupForm : Form
>    {
>        #region public variables
>        DateTime zeroTime = DateTime.Parse("00:00");  // Don't think this is the best way of setting a time to midnight
>        TaskType myTaskType = new TaskType();
>        DataConnector dc1 = new DataConnector();
>        #endregion
>
>        public StartupForm()
>        {
>            InitializeComponent();
>        }
>
>        private void StartupForm_Load(object sender, EventArgs e)
>        {
>            StartTime.Value = zeroTime;
>            EndTime.Value = zeroTime;
>
>            // playing
>            string myTest = myTaskType.GetOneType(3); // get an item directly from the class
>            myTaskType.AddOneType("Adding item 1");  // Add a new item directly
>            cboTaskType.DataSource = dc1;
>            dc1.DataSource = myTaskType.Types;  // set the class to be a DataConnector for some reason, VS2005 way of doing things
>            dc1.Position = dc1.Add("Adding item 2");  // Add a new item via the DataConnector and set the current position to be that new item
>        }
>
>        #region re-size management
>        /// <summary>
>        /// Form is being resized, allow anything but minimize
>        /// If the user minimized the form then send it to the system tray
>        /// </summary>
>        /// <param name="sender"></param>
>        /// <param name="e"></param>
>        private void StartupForm_Resize(object sender, EventArgs e)
>        {
>            if (WindowState == FormWindowState.Minimized)
>            {
>                ShowInTaskbar = false;
>                NotifySysTray.Visible = true;
>            }
>            else
>            {
>                this.ShowInTaskbar = true;
>                NotifySysTray.Visible = false;
>            }
>        }
>/// <summary>
>/// Close the form from the sys tray icon
>/// </summary>
>/// <param name="sender"></param>
>/// <param name="e"></param>
>        private void MenuSysTray_Close_Click(object sender, EventArgs e)
>        {
>            this.Close();
>        }
>/// <summary>
>/// Restore the Time record to previous state
>/// </summary>
>/// <param name="sender"></param>
>/// <param name="e"></param>
>        private void MenuSysTray_Restore_Click(object sender, EventArgs e)
>        {
>            WindowState = FormWindowState.Normal;
>            StartupForm_Resize(sender, e);
>        }
>        #endregion
>
>        #region Button control
>        private void btnClose_Click(object sender, EventArgs e)
>        {
>            this.Close();
>        }
>        #endregion
>    }
>
>    #region tasktype class - Lists all the task that I currently undertake and may be added to, hence serializable
>    [Serializable]  // Still got to learn how to do this, and what its really about - Think its some kind of XML write to file
>    public class TaskType
>    {
>        private ArrayList _types = new ArrayList();
>        private int _myVar;
>        private string _myString = "John";
>
>        public TaskType()
>        {
>            _types.Add("Dev MRP v1.2");
>            _types.Add("Dev MRP v1.1 (retro fix)");
>            _types.Add("Dev MRP v1.0 (retro fix)");
>            _types.Add("Dev (retro fix) pre MRP<v8.2");
>            _types.Add("QA v1.2");
>            _types.Add("(Support) Previous version(s)");
>            _types.Add("(BUG) New version issue ");
>            _types.Add("General Admin");
>            _types.Add("Holiday (When I'm lucky)");
>        }
>
>        public int MyVar
>        {
>            get { return _myVar; }
>            set { _myVar = value; }
>        }
>
>        public ArrayList Types
>        {
>            get { return _types; }
>        }
>
>        public string GetOneType(int recordno)
>        {
>            if (recordno < Types.Count)
>                return (string)_types[recordno];
>            else
>                return "";
>        }
>
>        public int AddOneType(string value)
>        {
>
>            return _types.Add(value); ;
>        }
>
>        public string MyString
>        {
>            get { return _myString; }
>            set { _myString = value; }
>        }
>
>    }
>    #endregion
>}
>
>If you would like the current project solution in zip format I can send in private email. BTW I do not consider this good code, its just a first pass at learning some principles. Really need to understand serialization a lot more and how to turn this into a wider scope class with different tasks going on. Give me a chance I'm learning and play, and its all fun and right now enjoyable :-)
>Yours always
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform