Hi there all,

First of all, I need to say that I'm so happy to join you... Second, I have a problem...
First I created a form page with a constructor that fills the listbox in it... As you can imagine all stuff begins after filling it... However, a friend of mine said that it will be good to add a Tabcontrol into that form... I add it and "copy-paste" all the form controls in it... But now I cant access them, plus listbox is empty... :( Please help...

TABCONTROL-FORM-ADO.NET stuff...

SqlDataAdapter cmd = new SqlDataAdapter("Select * From Ilgililer Where IlgiliOlMustId = @MusteriId", baglanti); // bağlı işlemler
            cmd.SelectCommand.Parameters.AddWithValue("@MusteriId", p);
            if (baglanti.State == System.Data.ConnectionState.Closed)
                baglanti.Open();
            DataTable dat = new DataTable();
            cmd.Fill(dat);
           listBox1.DisplayMember = dat.Columns["IlgiliAd"].ToString();
            listBox1.ValueMember = dat.Columns["IlgiliId"].ToString();
            listBox1.DataSource = dat;
            if (baglanti.State == System.Data.ConnectionState.Open)
                baglanti.Close();

Do you get any data into DataTable? Use a break point, hover the mouse ovher "dat" variable, and click on Magnifying glass to see if there is any data inside. If its not, your query is not corrct, or database is empty.

Check that 1st.

Did you "Copy & paste" or a "cut & paste" ??

If it is a copy and paste and you former controls is hidden beneath the tabform, it may actually be OK but not visible. What you see and try to access will in that case be the copy....

I've found it!!! :D:D:D
The problem was descriptions... Here is the solution:
I hope that might be helpfull for the others like me... :D The scenary is that I have alistview in form1 when I right click the listviewitem with a contextmenustrip, opens form2 which has a tabcontrol int it with a constructor bla... bla...

SqlDataAdapter cmd = new SqlDataAdapter("Select * From Ilgililer Where IlgiliOlMustId = @MusteriId", baglanti); // bağlı işlemler
            cmd.SelectCommand.Parameters.AddWithValue("@MusteriId", p);//constructor
            if (baglanti.State == System.Data.ConnectionState.Closed)
                baglanti.Open();
            DataTable dat = new DataTable();
            cmd.Fill(dat);
            (tabControl1.TabPages["tabPage1"].Controls["listBox1"] as ListBox).DisplayMember = dat.Columns["IlgiliAd"].ToString();
            (tabControl1.TabPages["tabPage1"].Controls["listBox1"] as ListBox).ValueMember = dat.Columns["IlgiliId"].ToString();
            listBox1.DataSource = dat;
            if (baglanti.State == System.Data.ConnectionState.Open)
                baglanti.Close();

BY THE WAY, THANKS MITJA ANYWAY... :D

Thanks bridgekeeper... :)

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.