Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Adding controls to panel

Posted on 2007-11-28
5
Medium Priority
?
882 Views
Last Modified: 2011-08-18
The section of code
                event_list_panel.Controls.Add(d_event_title[rowCount]);
                event_list_panel.Controls.Add(d_event_type[rowCount]);
                event_list_panel.Controls.Add(d_event_location[rowCount]);
                event_list_panel.Controls.Add(d_event_remove[rowCount]);
is only adding the first item in the list of four.

Why?
What am I missing?
private void mainForm_Load(object sender, EventArgs e)
        {
            int _x = 100;
            int _y = 100;
            int rowCount = 0;
            int screenWidth = (this.ClientSize.Width - (_x*2));
 
            ADODB.Recordset rs = new ADODB.Recordset();
            Connection = new ADODB.Connection();
            Connection.Open("NKTConnections", null, null, 0);
            string sql = "SELECT d.event_id, d.event_title, d.event_type, d.event_location FROM events_calendar_data d, events_calendar_datetime t where d.event_id = t.event_id ORDER BY t.event_date DESC, d.event_title;";
            rs.CursorLocation = CursorLocationEnum.adUseClient;
            rs.Open(sql, Connection, CursorTypeEnum.adOpenForwardOnly, LockTypeEnum.adLockReadOnly, 0);
            int _recordCount = rs.RecordCount;
 
            Label[] d_event_title = new Label[_recordCount];
            Label[] d_event_type = new Label[_recordCount];
            Label[] d_event_location = new Label[_recordCount];
            Label[] d_event_remove = new Label[_recordCount];
            Button[] d_event_edit = new Button[_recordCount];
            CheckBox[] d_event_cb_remove = new CheckBox[_recordCount];
 
            while (!rs.EOF)
            {
                string event_id = rs.Fields["event_id"].Value.ToString();
                string event_title = rs.Fields["event_title"].Value.ToString();
                string event_type = rs.Fields["event_type"].Value.ToString();
                string event_location = rs.Fields["event_location"].Value.ToString();
 
                d_event_title[rowCount] = new Label();
                d_event_type[rowCount] = new Label();
                d_event_location[rowCount] = new Label();
                d_event_remove[rowCount] = new Label();
                d_event_edit[rowCount] = new Button();
                d_event_cb_remove[rowCount] = new CheckBox();
 
                d_event_title[rowCount].Font = new Font("Arial", 10, FontStyle.Bold);
                d_event_title[rowCount].Text = event_title;
                d_event_title[rowCount].Location = new System.Drawing.Point(_x, _y);
                d_event_title[rowCount].Width = screenWidth;
 
                d_event_type[rowCount].Font = new Font("Arial", 8, FontStyle.Bold);
                d_event_type[rowCount].Text = event_type;
                d_event_type[rowCount].Location = new System.Drawing.Point(_x, _y+10);
                d_event_type[rowCount].Width = screenWidth;
 
                d_event_location[rowCount].Font = new Font("Arial", 8, FontStyle.Bold);
                d_event_location[rowCount].Text = event_location;
                d_event_location[rowCount].Location = new System.Drawing.Point(_x, _y+20);
                d_event_location[rowCount].Width = screenWidth;
 
                d_event_remove[rowCount].Font = new Font("Arial", 6, FontStyle.Regular);
                d_event_remove[rowCount].Text = "Check to Remove";
                d_event_remove[rowCount].Location = new System.Drawing.Point(_x, _y+30);
                d_event_remove[rowCount].Width = screenWidth;
 
                event_list_panel.Controls.Add(d_event_title[rowCount]);
                event_list_panel.Controls.Add(d_event_type[rowCount]);
                event_list_panel.Controls.Add(d_event_location[rowCount]);
                event_list_panel.Controls.Add(d_event_remove[rowCount]);
                
                _y += 100;
                rowCount++;
                rs.MoveNext();
            }
            rs.Close();
         }

Open in new window

0
Comment
Question by:nplib
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20368767
How do you know?, maybe them are present but with null string?
0
 
LVL 17

Author Comment

by:nplib
ID: 20368803
because I did a lot of testing to be sure.

if I do this
               
               //event_list_panel.Controls.Add(d_event_title[rowCount]);
                event_list_panel.Controls.Add(d_event_type[rowCount]);
                event_list_panel.Controls.Add(d_event_location[rowCount]);
                event_list_panel.Controls.Add(d_event_remove[rowCount]);
then the next one shows but not the following two don't show,

if I do this.

               //event_list_panel.Controls.Add(d_event_title[rowCount]);
               //event_list_panel.Controls.Add(d_event_type[rowCount]);
                event_list_panel.Controls.Add(d_event_location[rowCount]);
                event_list_panel.Controls.Add(d_event_remove[rowCount]);
then the first availble one shows but not the last, and if I comment out the first three then the last one shows, I've even reordered them to see what happens, and always the first one in the list is added but not the others.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20368914
have you tried with AddRange?
0
 
LVL 17

Author Comment

by:nplib
ID: 20368929
I've looked into it, but I don't know enough about it, I was having trouble finding good examples with what I needed.
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 1000 total points
ID: 20369298
event_list_panel.Controls.AddRange(new Control[] {d_event_title[rowCount], d_event_type[rowCount],d_event_location[rowCount] });
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question