Click here to Skip to main content
15,883,979 members
Home / Discussions / C#
   

C#

 
QuestionRe: genetic algorithm using C# Pin
ZurdoDev18-Feb-15 1:59
professionalZurdoDev18-Feb-15 1:59 
AnswerRe: genetic algorithm using C# Pin
CHill6018-Feb-15 2:12
mveCHill6018-Feb-15 2:12 
Questionhelp on WebBrowser Controller to select a value on a drop down list Pin
Member 1144865317-Feb-15 18:47
Member 1144865317-Feb-15 18:47 
AnswerRe: help on WebBrowser Controller to select a value on a drop down list Pin
Richard MacCutchan17-Feb-15 22:45
mveRichard MacCutchan17-Feb-15 22:45 
QuestionThreads vs. Tasks Article Pin
Kevin Marois17-Feb-15 18:03
professionalKevin Marois17-Feb-15 18:03 
AnswerRe: Threads vs. Tasks Article Pin
Pete O'Hanlon17-Feb-15 20:22
mvePete O'Hanlon17-Feb-15 20:22 
GeneralRe: Threads vs. Tasks Article Pin
Kevin Marois18-Feb-15 5:30
professionalKevin Marois18-Feb-15 5:30 
QuestionList Box showing Value and Display members? Pin
uniflare17-Feb-15 6:21
uniflare17-Feb-15 6:21 
Ok this is a CONCEPT problem (the code is not professional, just read it for the concept, though it does compile and run).

Right, I have asked many people on IRC and no one is giving me a straight answer lol so maybe some professionals can help me.

I am trying to use a Datasource property for my combobox. This is so I can just pass an entire KeyValue pair with indexes and values to be shown in the listbox.

Creating the keyvaluepair as a WHOLE and passing that to datasource property works perfectly.

Creating a keyvaluepair PROCEDURALLY (in a loop or w/e) ends in the datasource property ToString()ing it, list box items show BOTH value AND display members in square brackets as an entire option.

NOTE: Getting the lsitbox.value results in ONLY the valuemember being returned even though the listbox shows both the valuemembers AND the displaymember? it knows they are different?

Now, I dont want any alternatives or comments about the quality of the code, all I want to know is WHY is it doing this, it seems compeltely illogical that the same TYPE and Values and can different Effects within the datasource property? Its like it knows it was built procedurally?

Anyway here is some code for reference:

C#
// Windows Form

namespace skbtInstaller
{
    public partial class frmMainWindow : Form
    {
        public frmMainWindow()
        {
            InitializeComponent();
	
	    // coxArmaPath = Combo Box (simple drop down)
            this.cBoxArmaPath.ValueMember = "Key";
            this.cBoxArmaPath.DisplayMember = "Value";
	    // ....
        }

        public void addServerPathItem(String Key, String Value)
	{
            this.cBoxArmaPath.Items.Add(new KeyValuePair<String, String>(Key,Value));
	    // This works fine, only the "DisplayMember" is displayed and the "ValueMember" is hidden.
        }

	// This acts differently with the same types???
        public void setServerPathDatasource(List<KeyValuePair<String, String>> source)
        {
            this.cBoxArmaPath.DataSource = new BindingSource(source, null);
        }
    }

    public class skbtServerControl
    {
        private frmMainWindow frmMainWindowHandle;
        public void refreshformWindow()
        {
            // Clear Drop Box (empties drop box)
            this.frmMainWindowHandle.clearPathBox();

	    //skbtServerConfig is very simple property object
            foreach (KeyValuePair<String, skbtServerConfig> pair in CoreConfig.getServerConfigList())
            {
                // Populate Drop Box
                this.frmMainWindowHandle.addServerPathItem(pair.Key, pair.Value.getTextualName()); // this works as intended
                // cBox gets items like: Some Display Text, Some Display Text, Some Display Text (PERFECT!)
            }
        }
	
	// This works absolutely fine. ValueMembers are hidden.
        public void refreshformWindowWithSTATICDatasource()
        {
            // Clear Drop Box
            this.frmMainWindowHandle.clearPathBox();

            var pathDataSource = new List<KeyValuePair<String, String>>() 
            {
                new KeyValuePair<String, String>("testKey1", "somevalue1"),
                new KeyValuePair<String, String>("testKey2", "somevalue2"),
                new KeyValuePair<String, String>("testKey3", "somevalue3")
            };

            // Populate Drop Box
            this.frmMainWindowHandle.setServerPathDatasource(pathDataSource);
	    // cBox gets items like: Some Display Text, Some Display Text, Some Display Text (PERFECT!)
        }
	
	// ** HERE IS THE PROBLEM?? **
	// This creates a type that seems different to the above function which works fine...
        public void refreshformWindowWithDatasource()
        {
            // Clear Drop Box
            this.frmMainWindowHandle.clearPathBox();

            var pathDataSource = new List<KeyValuePair<String, String>>();

            //skbtServerConfig is very simple property object
            foreach (KeyValuePair<String, skbtServerConfig> pair in CoreConfig.getServerConfigList())
            {
                pathDataSource.Add(new KeyValuePair<String, String>(pair.Key, pair.Value.getTextualName()));
            }

            // Populate Drop Box
            this.frmMainWindowHandle.setServerPathDatasource(pathDataSource);
	    // cBox gets items like [asjAETJQ5785d45,Some Display Text], [asawfgQ5785d45,Some Display Text], [asjAhrrQ5785d45,Some Display Text]
	    // ????? surely this function should act exactly like the function above??
        }
    }
}

Chemical Bliss
aka Uniflare

AnswerRe: List Box showing Value and Display members? Pin
Richard Andrew x6417-Feb-15 6:34
professionalRichard Andrew x6417-Feb-15 6:34 
AnswerRe: List Box showing Value and Display members? Pin
Pete O'Hanlon17-Feb-15 6:54
mvePete O'Hanlon17-Feb-15 6:54 
GeneralRe: List Box showing Value and Display members? Pin
uniflare17-Feb-15 10:21
uniflare17-Feb-15 10:21 
GeneralRe: List Box showing Value and Display members? Pin
Pete O'Hanlon17-Feb-15 10:32
mvePete O'Hanlon17-Feb-15 10:32 
GeneralRe: List Box showing Value and Display members? Pin
uniflare17-Feb-15 11:29
uniflare17-Feb-15 11:29 
AnswerRe: List Box showing Value and Display members? Pin
seemajoshii17-Feb-15 19:09
seemajoshii17-Feb-15 19:09 
QuestionLogin to asp.net application through a link send via email Pin
User 1098516717-Feb-15 5:01
User 1098516717-Feb-15 5:01 
AnswerRe: Login to asp.net application through a link send via email Pin
Afzaal Ahmad Zeeshan17-Feb-15 5:33
professionalAfzaal Ahmad Zeeshan17-Feb-15 5:33 
QuestionVisual studio 2010 C# identity without hyphen Pin
sdfsdfsdfewrew3feff16-Feb-15 15:55
sdfsdfsdfewrew3feff16-Feb-15 15:55 
AnswerRe: Visual studio 2010 C# identity without hyphen Pin
Dave Kreskowiak16-Feb-15 16:12
mveDave Kreskowiak16-Feb-15 16:12 
GeneralRe: Visual studio 2010 C# identity without hyphen Pin
sdfsdfsdfewrew3feff17-Feb-15 2:54
sdfsdfsdfewrew3feff17-Feb-15 2:54 
GeneralRe: Visual studio 2010 C# identity without hyphen Pin
Dave Kreskowiak17-Feb-15 6:56
mveDave Kreskowiak17-Feb-15 6:56 
GeneralRe: Visual studio 2010 C# identity without hyphen Pin
sdfsdfsdfewrew3feff17-Feb-15 7:09
sdfsdfsdfewrew3feff17-Feb-15 7:09 
GeneralRe: Visual studio 2010 C# identity without hyphen Pin
Dave Kreskowiak17-Feb-15 7:11
mveDave Kreskowiak17-Feb-15 7:11 
GeneralRe: Visual studio 2010 C# identity without hyphen Pin
sdfsdfsdfewrew3feff17-Feb-15 7:17
sdfsdfsdfewrew3feff17-Feb-15 7:17 
GeneralRe: Visual studio 2010 C# identity without hyphen Pin
Mark_Wallace17-Feb-15 9:44
Mark_Wallace17-Feb-15 9:44 
GeneralRe: Visual studio 2010 C# identity without hyphen Pin
Dave Kreskowiak17-Feb-15 9:49
mveDave Kreskowiak17-Feb-15 9:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.