Click here to Skip to main content
15,907,396 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear People

I'm facing a big problem...

I have created a C# Project. In this project I have a Form1 (inside this form I have a Button1, Panel1 and ListView1), a reusable UserControl1 (inside this usercontrol I have 10 buttons such as: Button1, Button2, Button3, etc, etc ..) and also I have a Access 2007 Database (In my database I have a table created with 10 records).

What I have done so far is:

- From Form1 the Button1_Click event calls UserControl1 and displays it (inside Panel1) into my Form1.

What I'm trying to achieve is this:

- The 10 buttons in UserControl1 to be linked dynamically with my Database, what I mean by dynamically is that I dont want to create for every button_click event an opening db connection, exec query, and so on, but to create one and only one SQL query (lest say like an array query) so when I click Button1 to get the rocord1 from database table and display it into my ListView1, same for Button2, Button3 and so on...

Here is the code of my C# project:


Form1


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;
using System.Windows.Controls;
using Microsoft.VisualBasic.PowerPacks;
using System.Data.OleDb;
using System.Data.Common;
using System.Windows.Forms.Integration;
public partial class DtposMDIParentSystem : Form
{        
     public DtposMDIParentSystem()
     {
          InitializeComponent();            
     }
     private void DtposMDIParentSystem_Load(object sender, EventArgs e)
     {
          this.Panel1.Location = new System.Drawing.Point(332, 127);
          this.Panel1.Name = "Panel1";
          this.Panel1.Size = new System.Drawing.Size(700, 560);
     }

     UserControl1 userC = new UserControl();
     //----------------------------------------------------------//
     private void Button1_Click(object sender, EventArgs e)
     {
            this.Panel1.Visible = true;
            this.userC.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.userC.Location = new System.Drawing.Point(0, 0);
            this.userC.Size = new System.Drawing.Size(696, 556);
            this.userC.Enabled = true;
            this.userC.Visible = true;
            this.Panel1.Controls.Add(userC);
     }
}


The declaration of ListView1 on Form1.Designer.cs



this.ListView1 = new System.Windows.Forms.ListView();

// ListView1
this.ListView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top 
                        | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
this.ListView1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(128)))));
this.ListView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.colHeaderNumber,
this.colHeaderItem,
this.colHeaderPrice});
this.ListView1.FullRowSelect = true;
this.ListView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.ListView1.Location = new System.Drawing.Point(3, 5);
this.ListView1.Name = "ListView1";
this.ListView1.Size = new System.Drawing.Size(393, 300);
this.ListView1.TabIndex = 8;
this.ListView1.UseCompatibleStateImageBehavior = false;
this.ListView1.View = System.Windows.Forms.View.Details;

private System.Windows.Forms.ListView ListView1;




UserControl1


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;
using System.Data.OleDb;
using System.Data.Common;

public partial class UserControl1 : UserControl
{
        public UserControl1()
        {
            InitializeComponent();
        }

        private void UserControl1_Load(object sender, EventArgs e)
        {
            
        }
        
        private void Button1_Click(object sender, EventArgs e)
        {
            
        }

        private void Button2_Click(object sender, EventArgs e)
        {

        }

        private void Button3_Click(object sender, EventArgs e)
        {

        }
 .
 .
 .
}



If anyone can help me, it would mean the world to me...

Thanks in advance

Kind Regards

Agron
Posted
Updated 16-Dec-10 3:37am
v3
Comments
Hiren solanki 16-Dec-10 9:37am    
excluded 'code' tags inside 'pre' tag. :)

1 solution

This is the third time that you have asked essentially the same question.

The first one was here[^] on the 10/12/2010 and then again a couple of days ago.

Both times you got answers that seem reasonable to me.

Now either you are some kind of Troll, or programming really isn't the right employment/hobby choice for you. There is, I suppose, the possibility that you are unable to describe your problem correctly.

Whichever it is I am disinclined to give a helpful answer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900