.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 1st, 2012, 10:31 AM
conta conta is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2010
Posts: 13 conta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 56 m 31 sec
Reputation Power: 0
Combobox changing its index by itself

hi,

i have ComboBox in which I have names of employees.

I created ComboBox_SelectedIndexChanged so when I pick something from ComboBox, I take employee and do something [write somethin into TextBox]

Works fine, but I have problem when I have employees with same name: when I click to TextBox or some button, SelectedIndex is changed to index of employee with same name, but smaller index [i mean the one that is "upper" in ComboBox items]!

Any idea why? Can I make this behaviour stop?

For Combobox I have this class, because I need to show and receive different stuff:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Diploma
{
    //own class for combobox to show and use different item
    class ComboBoxItem
    {
        private string name; // sth to show, eg employee name and surname
        private string value;  //eg: employee_id- make sure unique 

        public string Value
        {
            get { return this.value; }
            set { this.value = value; }
        }
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public ComboBoxItem(string nName, string nValue)
        {
            this.name = nName;
            this.value = nValue;
        }

        public override string ToString()
        {
            return this.name;
        }
    }
}


I have visual studio 2010, project is in C#

Reply With Quote
  #2  
Old April 1st, 2012, 04:27 PM
Ronster Ronster is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Location: Charlotte
Posts: 412 Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level)Ronster User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 2 h 6 m 13 sec
Reputation Power: 143
A combobox has two properties on the page... the *value* and the *text*. The text property is what is shown on the page to the user. The value property is how you interact with the combo box. I'm thinking the problem you're having is that maybe the value properties have to be unique?

While you could have two "John Smith" text properties, but not two "John Smith" value properties. You would get around this possibly by having an employee ID as the value property.

As a test... while creating the combobox, use a counter and increment and make that the value part, when you select, see if that gives the appropriate one.

Reply With Quote
  #3  
Old April 2nd, 2012, 07:53 AM
conta conta is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2010
Posts: 13 conta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 56 m 31 sec
Reputation Power: 0
thanks for ideas!

anyway I think I found out whats the reason of this behaviour:

i have AutoCompleteMode property set to SuggestAttach.

when set to None, behaviour is normal, nothing is changing. Any other work as I said earlier. Maybe someone had similar problem before?

I add stuff to ComboBox like this:
Code:
foreach (DataRow r in dt2.Rows)
                {
                    delEmpChooseComboBox.Items.Add(new ComboBoxItem(r["name"] + " " + r["surname"], r["employee_id"].ToString()));
                }


thing is that I use this to pick what employee I wanna delete - but, when I click on delete button, the employee is changed to employee with same name, but higher at the ComboBox, so I am not able to delete the one I wanna!

Thanks for ideas!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > Combobox changing its index by itself

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap