Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 11th, 2006, 12:34 PM
Authorized User
 
Join Date: May 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to ColdFusion
Default c# comboBox Initialization problem

I have two comboBox that are dependend on each other. If one changes the other changes as well. Now that is not a problem there what I can see, the problem is when this windowsform gets loaded and for some reason the selectedindex stands on 0 instead of -1 for a second before displayed where it gets to -1 as told. Now my problem here is how it can be selectedindex 0, this problem leads to the DialogResult being set to OK where it not should be.

Help would be appreciated.



The code:


        private void Initialize_comboBox_FindCustomerByName()
        {
            ArrayList cutomerIdList = customerLogic.GetCustomers();
            if (0 < cutomerIdList.Count)
            {
                ArrayList customers = new ArrayList();
                customers.Add(new Customer("Ny Kund"));
                foreach (int i in cutomerIdList)
                {
                    customers.Add(new Customer(i));
                }
                comboBox_FindCustomerByName.DataSource = customers;
                comboBox_FindCustomerByName.DisplayMember = "Name";
                comboBox_FindCustomerByName.ValueMember = "Id";
            }
            comboBox_FindCustomerByName.SelectedIndex = -1;
            comboBox_FindCustomerByName.Text = "Sök kund";
        }
        private void Initialize_comboBox_FindCustomerByNumber()
        {
            ArrayList cutomerIdList = customerLogic.GetCustomers_SortedByCustomerNumber( );
            if (0 < cutomerIdList.Count)
            {
                ArrayList customers = new ArrayList();
                customers.Add(new Customer("Ny Kund"));
                foreach (int i in cutomerIdList)
                {
                    customers.Add(new Customer(i));
                }
                comboBox_FindCustomerByNumber.DataSource = customers;
                comboBox_FindCustomerByNumber.DisplayMember = "CustomerNumber";
                comboBox_FindCustomerByNumber.ValueMember = "Id";
            }
            comboBox_FindCustomerByNumber.SelectedIndex = -1;
            comboBox_FindCustomerByNumber.Text = "Sök kund";
        }


       private void comboBox_FindCustomerByName_SelectedIndexChanged(o bject sender, System.EventArgs e)
        {
            if (!comboBox_FindCustomerByName.SelectedIndex.Equals (-1))
            {
                button_Save.Enabled = true;
                if (comboBox_FindCustomerByName.SelectedValue.Equals(-2))
                {
                    this.DialogResult = DialogResult.No;
                    currentCustomer = null;
                }
                else
                {
                    comboBox_FindCustomerByNumber.SelectedValue = comboBox_FindCustomerByName.SelectedValue;
                    currentCustomer = (Customer)comboBox_FindCustomerByNumber.SelectedIt em;
                    this.DialogResult = DialogResult.OK;
                }
            }
            else
            {
                button_Save.Enabled = false;
                this.DialogResult = DialogResult.No;
            }
        }
        private void comboBox_FindCustomerByNumber_SelectedIndexChanged (object sender, System.EventArgs e)
        {
            if (!comboBox_FindCustomerByNumber.SelectedIndex.Equa ls(-1))
            {
                button_Save.Enabled = true;
                if (comboBox_FindCustomerByNumber.SelectedValue.Equal s(-2))
                {
                    this.DialogResult = DialogResult.No;
                    currentCustomer = null;
                }
                else
                {
                    comboBox_FindCustomerByName.SelectedValue = comboBox_FindCustomerByNumber.SelectedValue;
                    currentCustomer = (Customer)comboBox_FindCustomerByName.SelectedItem ;
                    this.DialogResult = DialogResult.OK;
                }
            }
            else
            {
                button_Save.Enabled = false;
                this.DialogResult = DialogResult.No;
            }
        }

 
Old May 11th, 2006, 12:44 PM
Authorized User
 
Join Date: May 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to ColdFusion
Default

sry seams I've posted in the wrong area.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Chapter 3 Type Initialization error canyiah BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 7 April 9th, 2009 06:07 PM
ComboBox Problem sfl234 C# 2 January 6th, 2007 01:22 PM
Property initialization problem VoodooCreator Pro Visual Basic 2005 1 June 29th, 2006 07:56 PM
problem about combobox nucharee General .NET 2 October 1st, 2004 04:05 AM
Minor User Control Initialization Problem Ron Howerton VB.NET 2002/2003 Basics 4 May 10th, 2004 07:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.