This may be a simple question, but I'm trying to populate a combo box with an array of string variables, but only that pass a conditional test. I'm getting a "complex databinding accepts as a datasource either in Ilist or IListSource" error.

Obviously this is not the right way to do this, but if someone could point me in the right direction, it would be greatly appreciated.

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.Text == "First")
            {

            for (int count = 0; count < 4; count++)
            {
                if (passengerName[count] == null)
                {
                    comboBox2.DataSource = seatNumber[count];
                    comboBox2.SelectedIndex = 0;
                }
             }
         }

Thanks in advance!

Jim

So you have 2 comboBoxes. 1st is bound to dataSource and 2nd comboBox is populated with some values, regarding on comboBox1 selection.
Which values are these, what is seatNumber variable?
Can you please provide some more code?
thx
mitja

I just started coding in forms after spending time messing with console apps. I'll admit that I'm new at this, but I'm reading everything I can... there's so much information that it's hard to find an example of what I'm trying to do.
What also would be a good book to study C# on my own.

This is my code so far.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Lab7
{     
    public partial class Form1 : Form
    {
        string newPassengerName;
        string[] seatNumber = new string[] { "1A", "1B", "2A", "2B", "4A", "4B",
                "4C", "4D", "5A", "5B", "5C", "5D", "6A", "6B", "6C", "6D", "7A", "7B",
                "7C", "7D" };
        string[] passengerName = new string[] { null, null, null, null, null, null,
                null, null, null, null, null, null, null, null, null, null, null, null,
                null, null };           



        public Form1()
        {
            InitializeComponent();
        }
        
        private void comboBox1_Click(object sender, EventArgs e)
        {
        string[] flightClass = {"First", "Business"};
        comboBox1.DataSource = flightClass;	
        comboBox1.SelectedIndex=0;
        }

        private void textBox1_Leave(object sender, EventArgs e)
        {            
            if (textBox1.Text != "")
            {
                this.newPassengerName = textBox1.Text;                
                this.comboBox1.Focus();
            }             
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            string newPassengerName = textBox1.Text;
            if (newPassengerName == "")
            {
                MessageBox.Show("You must enter a passenger name");
                this.textBox1.Focus();
            }
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (textBox1.Text != "")
                {
                    this.newPassengerName = textBox1.Text;
                    this.comboBox1.Focus();
                }
            }
        }

        private void comboBox2_Click(object sender, EventArgs e)
        {
           
                    
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.Text == "First")
            for (int count = 0; count < 4; count++)
            {
                if (passengerName[count] == null)
                {
                    comboBox2.DataSource = seatNumber[count];
                    comboBox2.SelectedIndex = 0;
                }
            }


        }
    }
}

What I can see from the code you gave me is, that you populate comboBox1 with only 2 valeus (first, business).
Then you have a string array of seat numbers.
QUESTION: With which values would you like to populate comboBox2? All of the seats which are empty?

If so, you should re-write the code completely.
But tell me 1st which values exactly you want to have in comboBox2, when "First" is selected in comboBox1?

What I can see from the code you gave me is, that you populate comboBox1 with only 2 valeus (first, business).
Then you have a string array of seat numbers.
QUESTION: With which values would you like to populate comboBox2? All of the seats which are empty?

If so, you should re-write the code completely.
But tell me 1st which values exactly you want to have in comboBox2, when "First" is selected in comboBox1?

Complete re-write in progress.

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.