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();
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