Cannot view data - c#

I have covered many tutorials and articles but can not find exactly what I need to assist me in resolving my issue.
My issue is that my compiled dll does not return rows of data from my SQL database file to the DataGridView.
I have created this project as a windows application for testing and it works fine. However, when I change the output to a class library it runs but does not return any data to the DataGridView. The header is there, because it is declared, but I have a feeling the compiled dll can not establish a connection to the database.
I have experience with C# and ASP but not in creating dll's.
To also clarify further, I can use the dataset or the bindingsource before I compile and view all the records using the Preview Data option. Is there a specific way you have to setup the database connection when creating a class library in my situation?
SQLDatabase.mdf Connection String:
Data Source=(localdb)\v11.0;Initial Catalog=SQLDatabase.mdf;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
Designer Generated Code: this.itemsTableAdapter.Fill(this.abDataSet.Items);
Please let me know if you would like me to post the Form.Designer.cs which was Designer Generated Code as well. Again, everything works fine as a Windows Application but as a Class Library the rows of data are never displayed in the DataGridView.
namespace AHPriceChecker4Free
{
public class AHPriceChecker : Core
{
private Thread formThread;
public void PluginStop()
{
Log("closed");
}
private AHCheckerForm ahForm;
public bool formIsOpen;
public void PluginRun()
{
formThread = new Thread(RunForm);
formThread.SetApartmentState(ApartmentState.STA);
formThread.Start();
formIsOpen = true;
while (formIsOpen)
{
Thread.Sleep(1000);
}
}
private void RunForm()
{
ahForm = new AHCheckerForm(this, me);
System.Windows.Forms.Application.Run(ahForm);
}
}
}
Form.cs
namespace AHPriceChecker4Free
{
partial class AHCheckerForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AHCheckerForm));
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.tsmMain = new System.Windows.Forms.ToolStripMenuItem();
this.tsmLoad = new System.Windows.Forms.ToolStripMenuItem();
this.tsmSave = new System.Windows.Forms.ToolStripMenuItem();
this.txtItemName = new System.Windows.Forms.TextBox();
this.btnSearch = new System.Windows.Forms.Button();
this.ofdOpen = new System.Windows.Forms.OpenFileDialog();
this.sfdSave = new System.Windows.Forms.SaveFileDialog();
this.btnMassSearch = new System.Windows.Forms.Button();
this.itemPriceHistory = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.itemAveragePrice = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.itemLastPrice = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.itemName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dgvAuctionTable = new System.Windows.Forms.DataGridView();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.label1 = new System.Windows.Forms.Label();
this.rtbSave = new System.Windows.Forms.RichTextBox();
this.tabPage3 = new System.Windows.Forms.TabPage();
this.label8 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.tabPage4 = new System.Windows.Forms.TabPage();
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.idDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.itemNameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.goldDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.silverDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.copperDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.perQtyDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.abchristDataSet = new AHPriceChecker4Free.abchristDataSet();
this.itemsTableAdapter = new AHPriceChecker4Free.abchristDataSetTableAdapters.ItemsTableAdapter();
this.itemsBindingSource1 = new System.Windows.Forms.BindingSource(this.components);
this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvAuctionTable)).BeginInit();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.tabPage3.SuspendLayout();
this.tabPage4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.abchristDataSet)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.itemsBindingSource1)).BeginInit();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tsmMain});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Padding = new System.Windows.Forms.Padding(7, 2, 0, 2);
this.menuStrip1.Size = new System.Drawing.Size(819, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
this.menuStrip1.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.menuStrip1_ItemClicked);
//
// tsmMain
//
this.tsmMain.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tsmLoad,
this.tsmSave});
this.tsmMain.Name = "tsmMain";
this.tsmMain.Size = new System.Drawing.Size(41, 20);
this.tsmMain.Text = "&Main";
//
// tsmLoad
//
this.tsmLoad.Name = "tsmLoad";
this.tsmLoad.Size = new System.Drawing.Size(123, 22);
this.tsmLoad.Text = "&Load data";
this.tsmLoad.Click += new System.EventHandler(this.tsmLoad_Click);
//
// tsmSave
//
this.tsmSave.Name = "tsmSave";
this.tsmSave.Size = new System.Drawing.Size(123, 22);
this.tsmSave.Text = "&Save data";
this.tsmSave.Click += new System.EventHandler(this.transferDataToSave);
//
// txtItemName
//
this.txtItemName.BackColor = System.Drawing.Color.LightYellow;
this.txtItemName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtItemName.Location = new System.Drawing.Point(8, 353);
this.txtItemName.Name = "txtItemName";
this.txtItemName.Size = new System.Drawing.Size(203, 20);
this.txtItemName.TabIndex = 2;
//
// btnSearch
//
this.btnSearch.BackColor = System.Drawing.Color.LightYellow;
this.btnSearch.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnSearch.Location = new System.Drawing.Point(217, 351);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(87, 25);
this.btnSearch.TabIndex = 5;
this.btnSearch.Text = "Search";
this.btnSearch.UseVisualStyleBackColor = false;
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// ofdOpen
//
this.ofdOpen.FileName = "openFileDialog1";
//
// sfdSave
//
this.sfdSave.FileOk += new System.ComponentModel.CancelEventHandler(this.sfdSave_FileOk);
//
// btnMassSearch
//
this.btnMassSearch.BackColor = System.Drawing.Color.LightYellow;
this.btnMassSearch.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnMassSearch.Location = new System.Drawing.Point(310, 351);
this.btnMassSearch.Name = "btnMassSearch";
this.btnMassSearch.Size = new System.Drawing.Size(105, 25);
this.btnMassSearch.TabIndex = 8;
this.btnMassSearch.Text = "Mass search";
this.btnMassSearch.UseVisualStyleBackColor = false;
this.btnMassSearch.Click += new System.EventHandler(this.btnMassSearch_Click);
//
// itemPriceHistory
//
this.itemPriceHistory.HeaderText = "Price History";
this.itemPriceHistory.Name = "itemPriceHistory";
this.itemPriceHistory.ReadOnly = true;
this.itemPriceHistory.Width = 350;
//
// itemAveragePrice
//
this.itemAveragePrice.HeaderText = "Average price";
this.itemAveragePrice.Name = "itemAveragePrice";
this.itemAveragePrice.ReadOnly = true;
this.itemAveragePrice.Width = 110;
//
// itemLastPrice
//
this.itemLastPrice.HeaderText = "Last price";
this.itemLastPrice.Name = "itemLastPrice";
//
// itemName
//
this.itemName.Frozen = true;
this.itemName.HeaderText = "Name";
this.itemName.Name = "itemName";
this.itemName.ReadOnly = true;
this.itemName.Width = 200;
//
// dgvAuctionTable
//
this.dgvAuctionTable.BackgroundColor = System.Drawing.Color.Cornsilk;
this.dgvAuctionTable.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvAuctionTable.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.itemName,
this.itemLastPrice,
this.itemAveragePrice,
this.itemPriceHistory});
this.dgvAuctionTable.Dock = System.Windows.Forms.DockStyle.Top;
this.dgvAuctionTable.Location = new System.Drawing.Point(3, 3);
this.dgvAuctionTable.Name = "dgvAuctionTable";
this.dgvAuctionTable.RowHeadersVisible = false;
this.dgvAuctionTable.Size = new System.Drawing.Size(805, 342);
this.dgvAuctionTable.TabIndex = 1;
this.dgvAuctionTable.CurrentCellDirtyStateChanged += new System.EventHandler(this.dgvAuctionTable_CurrentCellDirtyStateChanged);
//
**// *** REMOVED ALL TABS BUT THE ONE I AM HAVING AN ISSUE WITH TO REDUCE SIZE. THIS FORM BODY IS LIMITED TO 30000 CHARACTERS WHEN POSTING *** //
//**
// tabPage4
//
this.tabPage4.Controls.Add(this.dataGridView1);
this.tabPage4.Location = new System.Drawing.Point(4, 23);
this.tabPage4.Name = "tabPage4";
this.tabPage4.Padding = new System.Windows.Forms.Padding(3);
this.tabPage4.Size = new System.Drawing.Size(811, 381);
this.tabPage4.TabIndex = 3;
this.tabPage4.Text = "Database";
this.tabPage4.UseVisualStyleBackColor = true;
//
// dataGridView1
//
this.dataGridView1.AllowUserToAddRows = false;
this.dataGridView1.AllowUserToDeleteRows = false;
this.dataGridView1.AutoGenerateColumns = false;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.idDataGridViewTextBoxColumn,
this.itemNameDataGridViewTextBoxColumn,
this.goldDataGridViewTextBoxColumn,
this.silverDataGridViewTextBoxColumn,
this.copperDataGridViewTextBoxColumn,
this.perQtyDataGridViewTextBoxColumn});
this.dataGridView1.DataSource = this.itemsBindingSource1;
this.dataGridView1.Location = new System.Drawing.Point(66, 69);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.ReadOnly = true;
this.dataGridView1.RowHeadersVisible = false;
this.dataGridView1.Size = new System.Drawing.Size(669, 194);
this.dataGridView1.TabIndex = 0;
//
// idDataGridViewTextBoxColumn
//
this.idDataGridViewTextBoxColumn.DataPropertyName = "Id";
this.idDataGridViewTextBoxColumn.HeaderText = "Id";
this.idDataGridViewTextBoxColumn.Name = "idDataGridViewTextBoxColumn";
this.idDataGridViewTextBoxColumn.ReadOnly = true;
//
// itemNameDataGridViewTextBoxColumn
//
this.itemNameDataGridViewTextBoxColumn.DataPropertyName = "ItemName";
this.itemNameDataGridViewTextBoxColumn.HeaderText = "ItemName";
this.itemNameDataGridViewTextBoxColumn.Name = "itemNameDataGridViewTextBoxColumn";
this.itemNameDataGridViewTextBoxColumn.ReadOnly = true;
//
// goldDataGridViewTextBoxColumn
//
this.goldDataGridViewTextBoxColumn.DataPropertyName = "Gold";
this.goldDataGridViewTextBoxColumn.HeaderText = "Gold";
this.goldDataGridViewTextBoxColumn.Name = "goldDataGridViewTextBoxColumn";
this.goldDataGridViewTextBoxColumn.ReadOnly = true;
//
// silverDataGridViewTextBoxColumn
//
this.silverDataGridViewTextBoxColumn.DataPropertyName = "Silver";
this.silverDataGridViewTextBoxColumn.HeaderText = "Silver";
this.silverDataGridViewTextBoxColumn.Name = "silverDataGridViewTextBoxColumn";
this.silverDataGridViewTextBoxColumn.ReadOnly = true;
//
// copperDataGridViewTextBoxColumn
//
this.copperDataGridViewTextBoxColumn.DataPropertyName = "Copper";
this.copperDataGridViewTextBoxColumn.HeaderText = "Copper";
this.copperDataGridViewTextBoxColumn.Name = "copperDataGridViewTextBoxColumn";
this.copperDataGridViewTextBoxColumn.ReadOnly = true;
//
// perQtyDataGridViewTextBoxColumn
//
this.perQtyDataGridViewTextBoxColumn.DataPropertyName = "PerQty";
this.perQtyDataGridViewTextBoxColumn.HeaderText = "PerQty";
this.perQtyDataGridViewTextBoxColumn.Name = "perQtyDataGridViewTextBoxColumn";
this.perQtyDataGridViewTextBoxColumn.ReadOnly = true;
//
// abchristDataSet
//
this.abchristDataSet.DataSetName = "abchristDataSet";
this.abchristDataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
//
// itemsTableAdapter
//
this.itemsTableAdapter.ClearBeforeFill = true;
//
// itemsBindingSource1
//
this.itemsBindingSource1.DataMember = "Items";
this.itemsBindingSource1.DataSource = this.abchristDataSet;
//
// AHCheckerForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Cornsilk;
this.ClientSize = new System.Drawing.Size(819, 432);
this.Controls.Add(this.tabControl1);
this.Controls.Add(this.menuStrip1);
this.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MainMenuStrip = this.menuStrip1;
this.Name = "AHCheckerForm";
this.Text = "AHPriceChecker4Free - By Cobras.Club";
this.TopMost = true;
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.AHCheckerForm_FormClosed);
this.Load += new System.EventHandler(this.AHCheckerForm_Load);
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvAuctionTable)).EndInit();
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage1.PerformLayout();
this.tabPage2.ResumeLayout(false);
this.tabPage2.PerformLayout();
this.tabPage3.ResumeLayout(false);
this.tabPage3.PerformLayout();
this.tabPage4.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.abchristDataSet)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.itemsBindingSource1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem tsmMain;
private System.Windows.Forms.ToolStripMenuItem tsmLoad;
private System.Windows.Forms.TextBox txtItemName;
private System.Windows.Forms.Button btnSearch;
private System.Windows.Forms.OpenFileDialog ofdOpen;
private System.Windows.Forms.SaveFileDialog sfdSave;
private System.Windows.Forms.Button btnMassSearch;
private System.Windows.Forms.ToolStripMenuItem tsmSave;
private System.Windows.Forms.DataGridViewTextBoxColumn itemPriceHistory;
private System.Windows.Forms.DataGridViewTextBoxColumn itemAveragePrice;
private System.Windows.Forms.DataGridViewTextBoxColumn itemLastPrice;
private System.Windows.Forms.DataGridViewTextBoxColumn itemName;
private System.Windows.Forms.DataGridView dgvAuctionTable;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.RichTextBox rtbSave;
private System.Windows.Forms.TabPage tabPage3;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TabPage tabPage4;
private System.Windows.Forms.DataGridView dataGridView1;
private abchristDataSet abchristDataSet;
private abchristDataSetTableAdapters.ItemsTableAdapter itemsTableAdapter;
private System.Windows.Forms.DataGridViewTextBoxColumn idDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn itemNameDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn goldDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn silverDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn copperDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn perQtyDataGridViewTextBoxColumn;
private System.Windows.Forms.BindingSource itemsBindingSource1;
}
}

You have to add code in your class library that will let you set the connection string. The place to set the connection string is in the constructor of your class library. You can manually add the connection string like this in the app.config:
<connectionStrings>
<add name="MyDB" connectionString="Server=.\SQLExpress;
AttachDbFilename=C:\MyFolder\MyDataFile.mdf;Database=dbname;
Trusted_Connection=Yes;" />
</connectionStrings>
Then access the configuration string like this:
var str = ConfigurationManager.ConnectionStrings["MyDb"].ConnectionString

Related

Having trouble displaying a list of transactions to a list box in VisualStudios2019 winforms C# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 13 days ago.
Improve this question
I know I'm butchering the transaction class. I just have no idea what to do. Nothing gets displayed when I run the form and hit add new transaction. I appreciate any help here's my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AccountBalance
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnNewTran_Click(object sender, EventArgs e)
{
string strTransactionType = "";
if (rbDeposit.Checked)
{
strTransactionType = rbDeposit.Text;
}
else
{
strTransactionType = rbWithdrawal.Text;
}
Transaction newTransaction = new Transaction();
newTransaction.Amount = decimal.Parse(txtTAmount.Text);
newTransaction.Type = strTransactionType;
newTransaction.Date = txtTDate.Text;
lstTransactions.Items.Add(newTransaction);
decimal decBalance = decimal.Parse(lblCBalance.Text);
if (newTransaction.Type == "Deposit")
{
decBalance += newTransaction.Amount;
lblCBalance.Text = decBalance.ToString("c");
}
else
{
decBalance -= newTransaction.Amount;
lblCBalance.Text = decBalance.ToString("c");
}
if (decBalance < 0)
{
lblCBalance.ForeColor = Color.Red;
}
rbDeposit.Checked = false;
rbWithdrawal.Checked = false;
txtTAmount.Clear();
txtTDate.Clear();
txtTAmount.Focus();
}
private void btnRemTran_Click(object sender, EventArgs e)
{
int intSelectedIndex = lstTransactions.SelectedIndex;
Transaction selectedTransaction = (Transaction)lstTransactions.SelectedItem;
lstTransactions.Items.RemoveAt(intSelectedIndex);
decimal decBalance = decimal.Parse(lblCBalance.Text);
if (selectedTransaction.Type == "Deposit")
{
decBalance -= selectedTransaction.Amount;
lblCBalance.Text = decBalance.ToString("c");
}
else
{
decBalance += selectedTransaction.Amount;
lblCBalance.Text = decBalance.ToString("c");
}
if (decBalance >= 0)
{
lblCBalance.ForeColor = Color.Black;
}
}
private void btnClear_Click(object sender, EventArgs e)
{
rbDeposit.Checked = false;
rbWithdrawal.Checked = false;
txtTAmount.Clear();
txtTDate.Clear();
txtTAmount.Focus();
}
private void lstTransactions_Click(object sender, EventArgs e)
{
Transaction selectedTransaction = (Transaction)lstTransactions.SelectedItem;
if (selectedTransaction.Type == "Deposit")
{
rbDeposit.Checked = true;
}
else
{
rbWithdrawal.Checked = true;
}
txtTAmount.Text = selectedTransaction.Amount.ToString("c");
txtTDate.Text = selectedTransaction.Date;
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
public class Transaction
{
internal decimal Amount;
internal string Type;
internal string Date;
}
}
namespace AccountBalance
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblTDate = new System.Windows.Forms.Label();
this.txtTDate = new System.Windows.Forms.TextBox();
this.lblTAmount = new System.Windows.Forms.Label();
this.txtTAmount = new System.Windows.Forms.TextBox();
this.lblTType = new System.Windows.Forms.Label();
this.rbDeposit = new System.Windows.Forms.RadioButton();
this.rbWithdrawal = new System.Windows.Forms.RadioButton();
this.rbServFee = new System.Windows.Forms.RadioButton();
this.lblPayee = new System.Windows.Forms.Label();
this.txtPayee = new System.Windows.Forms.TextBox();
this.lblCheckNum = new System.Windows.Forms.Label();
this.txtCheckNum = new System.Windows.Forms.TextBox();
this.lblCBalance = new System.Windows.Forms.Label();
this.txtCBalance = new System.Windows.Forms.TextBox();
this.lstTransactions = new System.Windows.Forms.ListBox();
this.btnNewTran = new System.Windows.Forms.Button();
this.btnRemTran = new System.Windows.Forms.Button();
this.btnClear = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lblTDate
//
this.lblTDate.AutoSize = true;
this.lblTDate.Location = new System.Drawing.Point(12, 9);
this.lblTDate.Name = "lblTDate";
this.lblTDate.Size = new System.Drawing.Size(104, 13);
this.lblTDate.TabIndex = 0;
this.lblTDate.Text = "Date of Transaction:";
//
// txtTDate
//
this.txtTDate.Location = new System.Drawing.Point(15, 25);
this.txtTDate.Name = "txtTDate";
this.txtTDate.Size = new System.Drawing.Size(100, 20);
this.txtTDate.TabIndex = 1;
//
// lblTAmount
//
this.lblTAmount.AutoSize = true;
this.lblTAmount.Location = new System.Drawing.Point(263, 9);
this.lblTAmount.Name = "lblTAmount";
this.lblTAmount.Size = new System.Drawing.Size(105, 13);
this.lblTAmount.TabIndex = 0;
this.lblTAmount.Text = "Transaction Amount:";
//
// txtTAmount
//
this.txtTAmount.Location = new System.Drawing.Point(266, 25);
this.txtTAmount.Name = "txtTAmount";
this.txtTAmount.Size = new System.Drawing.Size(100, 20);
this.txtTAmount.TabIndex = 2;
//
// lblTType
//
this.lblTType.AutoSize = true;
this.lblTType.Location = new System.Drawing.Point(473, 9);
this.lblTType.Name = "lblTType";
this.lblTType.Size = new System.Drawing.Size(93, 13);
this.lblTType.TabIndex = 0;
this.lblTType.Text = "Transaction Type:";
//
// rbDeposit
//
this.rbDeposit.AutoSize = true;
this.rbDeposit.Location = new System.Drawing.Point(481, 28);
this.rbDeposit.Name = "rbDeposit";
this.rbDeposit.Size = new System.Drawing.Size(61, 17);
this.rbDeposit.TabIndex = 3;
this.rbDeposit.TabStop = true;
this.rbDeposit.Text = "Deposit";
this.rbDeposit.UseVisualStyleBackColor = true;
//
// rbWithdrawal
//
this.rbWithdrawal.AutoSize = true;
this.rbWithdrawal.Location = new System.Drawing.Point(481, 51);
this.rbWithdrawal.Name = "rbWithdrawal";
this.rbWithdrawal.Size = new System.Drawing.Size(78, 17);
this.rbWithdrawal.TabIndex = 4;
this.rbWithdrawal.TabStop = true;
this.rbWithdrawal.Text = "Withdrawal";
this.rbWithdrawal.UseVisualStyleBackColor = true;
//
// rbServFee
//
this.rbServFee.AutoSize = true;
this.rbServFee.Location = new System.Drawing.Point(481, 74);
this.rbServFee.Name = "rbServFee";
this.rbServFee.Size = new System.Drawing.Size(82, 17);
this.rbServFee.TabIndex = 5;
this.rbServFee.TabStop = true;
this.rbServFee.Text = "Service Fee";
this.rbServFee.UseVisualStyleBackColor = true;
//
// lblPayee
//
this.lblPayee.AutoSize = true;
this.lblPayee.Location = new System.Drawing.Point(12, 53);
this.lblPayee.Name = "lblPayee";
this.lblPayee.Size = new System.Drawing.Size(40, 13);
this.lblPayee.TabIndex = 0;
this.lblPayee.Text = "Payee:";
//
// txtPayee
//
this.txtPayee.Location = new System.Drawing.Point(15, 71);
this.txtPayee.Name = "txtPayee";
this.txtPayee.Size = new System.Drawing.Size(230, 20);
this.txtPayee.TabIndex = 6;
//
// lblCheckNum
//
this.lblCheckNum.AutoSize = true;
this.lblCheckNum.Location = new System.Drawing.Point(263, 53);
this.lblCheckNum.Name = "lblCheckNum";
this.lblCheckNum.Size = new System.Drawing.Size(81, 13);
this.lblCheckNum.TabIndex = 0;
this.lblCheckNum.Text = "Check Number:";
//
// txtCheckNum
//
this.txtCheckNum.Location = new System.Drawing.Point(266, 71);
this.txtCheckNum.Name = "txtCheckNum";
this.txtCheckNum.Size = new System.Drawing.Size(100, 20);
this.txtCheckNum.TabIndex = 7;
//
// lblCBalance
//
this.lblCBalance.AutoSize = true;
this.lblCBalance.Location = new System.Drawing.Point(12, 109);
this.lblCBalance.Name = "lblCBalance";
this.lblCBalance.Size = new System.Drawing.Size(86, 13);
this.lblCBalance.TabIndex = 0;
this.lblCBalance.Text = "Current Balance:";
//
// txtCBalance
//
this.txtCBalance.Location = new System.Drawing.Point(145, 102);
this.txtCBalance.Name = "txtCBalance";
this.txtCBalance.ReadOnly = true;
this.txtCBalance.Size = new System.Drawing.Size(100, 20);
this.txtCBalance.TabIndex = 0;
//
// lstTransactions
//
this.lstTransactions.FormattingEnabled = true;
this.lstTransactions.Location = new System.Drawing.Point(15, 125);
this.lstTransactions.Name = "lstTransactions";
this.lstTransactions.Size = new System.Drawing.Size(439, 316);
this.lstTransactions.TabIndex = 0;
//
// btnNewTran
//
this.btnNewTran.Location = new System.Drawing.Point(460, 171);
this.btnNewTran.Name = "btnNewTran";
this.btnNewTran.Size = new System.Drawing.Size(99, 23);
this.btnNewTran.TabIndex = 8;
this.btnNewTran.Text = "New Transaction";
this.btnNewTran.UseVisualStyleBackColor = true;
//
// btnRemTran
//
this.btnRemTran.Location = new System.Drawing.Point(460, 252);
this.btnRemTran.Name = "btnRemTran";
this.btnRemTran.Size = new System.Drawing.Size(99, 23);
this.btnRemTran.TabIndex = 9;
this.btnRemTran.Text = "Remove";
this.btnRemTran.UseVisualStyleBackColor = true;
//
// btnClear
//
this.btnClear.Location = new System.Drawing.Point(460, 333);
this.btnClear.Name = "btnClear";
this.btnClear.Size = new System.Drawing.Size(99, 23);
this.btnClear.TabIndex = 10;
this.btnClear.Text = "Clear";
this.btnClear.UseVisualStyleBackColor = true;
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(460, 414);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(99, 23);
this.btnExit.TabIndex = 11;
this.btnExit.Text = "Exit";
this.btnExit.UseVisualStyleBackColor = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(578, 450);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnClear);
this.Controls.Add(this.btnRemTran);
this.Controls.Add(this.btnNewTran);
this.Controls.Add(this.lstTransactions);
this.Controls.Add(this.txtCBalance);
this.Controls.Add(this.lblCBalance);
this.Controls.Add(this.txtCheckNum);
this.Controls.Add(this.lblCheckNum);
this.Controls.Add(this.txtPayee);
this.Controls.Add(this.lblPayee);
this.Controls.Add(this.rbServFee);
this.Controls.Add(this.rbWithdrawal);
this.Controls.Add(this.rbDeposit);
this.Controls.Add(this.lblTType);
this.Controls.Add(this.txtTAmount);
this.Controls.Add(this.lblTAmount);
this.Controls.Add(this.txtTDate);
this.Controls.Add(this.lblTDate);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label lblTDate;
private System.Windows.Forms.TextBox txtTDate;
private System.Windows.Forms.Label lblTAmount;
private System.Windows.Forms.TextBox txtTAmount;
private System.Windows.Forms.Label lblTType;
private System.Windows.Forms.RadioButton rbDeposit;
private System.Windows.Forms.RadioButton rbWithdrawal;
private System.Windows.Forms.RadioButton rbServFee;
private System.Windows.Forms.Label lblPayee;
private System.Windows.Forms.TextBox txtPayee;
private System.Windows.Forms.Label lblCheckNum;
private System.Windows.Forms.TextBox txtCheckNum;
private System.Windows.Forms.Label lblCBalance;
private System.Windows.Forms.TextBox txtCBalance;
private System.Windows.Forms.ListBox lstTransactions;
private System.Windows.Forms.Button btnNewTran;
private System.Windows.Forms.Button btnRemTran;
private System.Windows.Forms.Button btnClear;
private System.Windows.Forms.Button btnExit;
}
}
I pretty much tried to use quick fixes and watched some random videos and came up with nothing.
Don't add your items to the ListBox directly. Create an appropriate list and bind that to the ListBox, then add your items to that list. If you use a BindingList<Transaction> then adding an item to the list will automatically update the bound control, which will not happen with a List<Transaction>.
var transactions = new BindingList<Transaction>();
myListBox.DataSource = transactions;
By default, when you add an item to a ListBox, ToString is called on that object and the result displayed. If you don't override the ToString method, that will just be the name of the type. You can set the DisplayMember of the ListBox and the specified property value will be displayed, e.g.
var transactions = new BindingList<Transaction>();
myListBox.DisplayMember = nameof(Transaction.Amount);
myListBox.DataSource = transactions;
Note that only properties can be specified as the DisplayMember or ValueMember. Fields will not work.
If you want some custom text displayed then you need to override the ToString method and have it return the desired text.

SelectIndexChanged not working (C# desktop)

**The autopostback-fix does not work! **
I have a GUI that looks like:
I want to show the details of a cat when it's clicked on.
I used this code for it:
private void listBox_Cats_SelectedIndexChanged(object sender, System.EventArgs e)
{
// Get the currently selected item in the ListBox.
Cat cat = listBox_Cats.SelectedItem as Cat;
if (cat != null)
{
tb_ID.Text = cat.ID.ToString();
tb_Name.Text = cat.Name.ToString();
tb_DateArrived.Text = cat.DateArrived.ToString();
tb_IsAdopted.Text = cat.IsAdopted.ToString();
tb_adoptedBy.Text = cat.AdoptedBy.ToString();
}
}
When running however, nothing seems to work. What am I doing wrong?
EDIT
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using IntegrationTool;
namespace IntegrationTool
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
SqlConnection conn = new SqlConnection("Server=.\\SQLEXPRESS;Database=CatShelter;Integrated Security=true");
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM [dbo].[cats]", conn);
SqlDataReader reader = cmd.ExecuteReader();
List<Cat> cats = new List<Cat>();
while (reader.Read())
{
Cat c = new Cat();
c.ID = (int)reader["CatID"];
c.Name = (string)reader["Name"];
c.DateArrived = (DateTime)reader["DateArrived"];
c.IsAdopted = (string)reader["IsAdopted"];
c.AdoptedBy = (string)reader["AdoptedBy"];
cats.Add(c);
}
foreach (Cat c in cats)
{
Console.WriteLine(c.Name);
}
reader.Close();
conn.Close();
if (Debugger.IsAttached)
{
Console.ReadLine();
}
listBox_Cats.DataSource = cats;
listBox_Cats.DisplayMember = "Name";
listBox_Cats.ValueMember = "ID";
}
private void listBox_Cats_SelectedIndexChanged(object sender, System.EventArgs e)
{
// Get the currently selected item in the ListBox.
Cat cat = listBox_Cats.SelectedItem as Cat;
if (cat != null)
{
Console.WriteLine(cat.Name);
tb_ID.Text = cat.ID.ToString();
tb_Name.Text = cat.Name.ToString();
tb_DateArrived.Text = cat.DateArrived.ToString();
tb_IsAdopted.Text = cat.IsAdopted.ToString();
tb_adoptedBy.Text = cat.AdoptedBy.ToString();
}
}
}
}
namespace IntegrationTool
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.listBox_Cats = new System.Windows.Forms.ListBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.button2 = new System.Windows.Forms.Button();
this.cb_VetCheck = new System.Windows.Forms.CheckBox();
this.label5 = new System.Windows.Forms.Label();
this.tb_Comment = new System.Windows.Forms.TextBox();
this.tb_ID = new System.Windows.Forms.TextBox();
this.tb_DateArrived = new System.Windows.Forms.TextBox();
this.tb_IsAdopted = new System.Windows.Forms.TextBox();
this.tb_adoptedBy = new System.Windows.Forms.TextBox();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.label6 = new System.Windows.Forms.Label();
this.tb_Name = new System.Windows.Forms.TextBox();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.SuspendLayout();
//
// listBox_Cats
//
this.listBox_Cats.FormattingEnabled = true;
this.listBox_Cats.Location = new System.Drawing.Point(16, 35);
this.listBox_Cats.Name = "listBox_Cats";
this.listBox_Cats.Size = new System.Drawing.Size(137, 316);
this.listBox_Cats.TabIndex = 0;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.tb_Name);
this.groupBox1.Controls.Add(this.label6);
this.groupBox1.Controls.Add(this.tb_adoptedBy);
this.groupBox1.Controls.Add(this.tb_IsAdopted);
this.groupBox1.Controls.Add(this.tb_DateArrived);
this.groupBox1.Controls.Add(this.tb_ID);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(252, 31);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(409, 190);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Details";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(6, 35);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(24, 13);
this.label1.TabIndex = 0;
this.label1.Text = "ID: ";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(6, 95);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(69, 13);
this.label2.TabIndex = 1;
this.label2.Text = "Date Arrived:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(6, 123);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(60, 13);
this.label3.TabIndex = 2;
this.label3.Text = "Is adopted:";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(6, 157);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(65, 13);
this.label4.TabIndex = 3;
this.label4.Text = "Adopted By:";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.tb_Comment);
this.groupBox2.Controls.Add(this.label5);
this.groupBox2.Controls.Add(this.cb_VetCheck);
this.groupBox2.Location = new System.Drawing.Point(252, 243);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(409, 157);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Validate";
//
// button2
//
this.button2.Location = new System.Drawing.Point(553, 424);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(107, 31);
this.button2.TabIndex = 4;
this.button2.Text = "Save";
this.button2.UseVisualStyleBackColor = true;
//
// cb_VetCheck
//
this.cb_VetCheck.AutoSize = true;
this.cb_VetCheck.Location = new System.Drawing.Point(9, 30);
this.cb_VetCheck.Name = "cb_VetCheck";
this.cb_VetCheck.Size = new System.Drawing.Size(76, 17);
this.cb_VetCheck.TabIndex = 0;
this.cb_VetCheck.Text = "Vet Check";
this.cb_VetCheck.UseVisualStyleBackColor = true;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(6, 75);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(51, 13);
this.label5.TabIndex = 1;
this.label5.Text = "Comment";
//
// tb_Comment
//
this.tb_Comment.Location = new System.Drawing.Point(9, 91);
this.tb_Comment.Name = "tb_Comment";
this.tb_Comment.Size = new System.Drawing.Size(288, 20);
this.tb_Comment.TabIndex = 2;
//
// tb_ID
//
this.tb_ID.Location = new System.Drawing.Point(81, 35);
this.tb_ID.Name = "tb_ID";
this.tb_ID.ReadOnly = true;
this.tb_ID.Size = new System.Drawing.Size(66, 20);
this.tb_ID.TabIndex = 4;
//
// tb_DateArrived
//
this.tb_DateArrived.Location = new System.Drawing.Point(81, 92);
this.tb_DateArrived.Name = "tb_DateArrived";
this.tb_DateArrived.ReadOnly = true;
this.tb_DateArrived.Size = new System.Drawing.Size(66, 20);
this.tb_DateArrived.TabIndex = 5;
//
// tb_IsAdopted
//
this.tb_IsAdopted.Location = new System.Drawing.Point(81, 120);
this.tb_IsAdopted.Name = "tb_IsAdopted";
this.tb_IsAdopted.ReadOnly = true;
this.tb_IsAdopted.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.tb_IsAdopted.Size = new System.Drawing.Size(66, 20);
this.tb_IsAdopted.TabIndex = 6;
//
// tb_adoptedBy
//
this.tb_adoptedBy.Location = new System.Drawing.Point(81, 154);
this.tb_adoptedBy.Name = "tb_adoptedBy";
this.tb_adoptedBy.ReadOnly = true;
this.tb_adoptedBy.Size = new System.Drawing.Size(66, 20);
this.tb_adoptedBy.TabIndex = 7;
//
// groupBox3
//
this.groupBox3.Controls.Add(this.listBox_Cats);
this.groupBox3.Location = new System.Drawing.Point(12, 31);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(175, 369);
this.groupBox3.TabIndex = 5;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Cats";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(7, 61);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(41, 13);
this.label6.TabIndex = 8;
this.label6.Text = "Name: ";
//
// tb_Name
//
this.tb_Name.Location = new System.Drawing.Point(81, 61);
this.tb_Name.Name = "tb_Name";
this.tb_Name.ReadOnly = true;
this.tb_Name.Size = new System.Drawing.Size(66, 20);
this.tb_Name.TabIndex = 9;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(721, 480);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.button2);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ListBox listBox_Cats;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox tb_adoptedBy;
private System.Windows.Forms.TextBox tb_IsAdopted;
private System.Windows.Forms.TextBox tb_DateArrived;
private System.Windows.Forms.TextBox tb_ID;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.TextBox tb_Comment;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.CheckBox cb_VetCheck;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.TextBox tb_Name;
private System.Windows.Forms.Label label6;
}
}
Your listBox_Cats_SelectedIndexChanged is not bound to the SelectedIndexChanged event of the listBox.
There should be entry in your designer file that looks like:
this.listBox_Cats.SelectedIndexChanged += new System.EventHandler(this.listBox_Cats_SelectedIndexChanged);
You can add it manually if it isn't already there - in InitializeComponent.
Your listbox(listBox_Cats) has Cat as a Complex type so try to get the selected item by below code and see it works.
Cat value = (Cat) this.listBox_Cats.SelectedItem;

c# chart axis not displaying when form is loaded

For some reason the axis and grid is not being displayed on the c# chart. as you can see from the two pictures, the background of the chart is being displayed, but nothing else is. Can anyone help me figure out why the grid and information from the chart is not being displayed?
The form from designer in visual studio:
The form at runtime:
namespace Harman.Generic.Framework.WaveformMaker
{
partial class WaveformMaker
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.mnuStrip = new System.Windows.Forms.MenuStrip();
this.mnuFile = new System.Windows.Forms.ToolStripMenuItem();
this.mnuFileSaveWaveform = new System.Windows.Forms.ToolStripMenuItem();
this.mnuFileExit = new System.Windows.Forms.ToolStripMenuItem();
this.btnRun = new System.Windows.Forms.Button();
this.lblPointVoltage = new System.Windows.Forms.Label();
this.lblPointDuration = new System.Windows.Forms.Label();
this.dgdPointList = new System.Windows.Forms.DataGridView();
this.colPoint = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colVoltage = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colDuration = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.btnRemovePoint = new System.Windows.Forms.Button();
this.btnAddPoint = new System.Windows.Forms.Button();
this.chWaveform = new System.Windows.Forms.DataVisualization.Charting.Chart();
this.mnuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgdPointList)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.chWaveform)).BeginInit();
this.SuspendLayout();
//
// contextMenuStrip1
//
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4);
//
// mnuStrip
//
this.mnuStrip.BackColor = System.Drawing.SystemColors.Control;
this.mnuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuFile});
this.mnuStrip.Location = new System.Drawing.Point(0, 0);
this.mnuStrip.Name = "mnuStrip";
this.mnuStrip.Size = new System.Drawing.Size(894, 24);
this.mnuStrip.TabIndex = 2;
this.mnuStrip.Text = "menuStrip1";
//
// mnuFile
//
this.mnuFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuFileSaveWaveform,
this.mnuFileExit});
this.mnuFile.Name = "mnuFile";
this.mnuFile.Size = new System.Drawing.Size(37, 20);
this.mnuFile.Text = "File";
//
// mnuFileSaveWaveform
//
this.mnuFileSaveWaveform.Name = "mnuFileSaveWaveform";
this.mnuFileSaveWaveform.Size = new System.Drawing.Size(156, 22);
this.mnuFileSaveWaveform.Text = "Save Waveform";
//
// mnuFileExit
//
this.mnuFileExit.Name = "mnuFileExit";
this.mnuFileExit.Size = new System.Drawing.Size(156, 22);
this.mnuFileExit.Text = "Exit";
//
// btnRun
//
this.btnRun.Location = new System.Drawing.Point(621, 562);
this.btnRun.Name = "btnRun";
this.btnRun.Size = new System.Drawing.Size(83, 23);
this.btnRun.TabIndex = 4;
this.btnRun.Text = "Run";
this.btnRun.UseVisualStyleBackColor = true;
//
// lblPointVoltage
//
this.lblPointVoltage.AutoSize = true;
this.lblPointVoltage.Location = new System.Drawing.Point(10, 572);
this.lblPointVoltage.Name = "lblPointVoltage";
this.lblPointVoltage.Size = new System.Drawing.Size(49, 13);
this.lblPointVoltage.TabIndex = 6;
this.lblPointVoltage.Text = "Voltage: ";
//
// lblPointDuration
//
this.lblPointDuration.AutoSize = true;
this.lblPointDuration.Location = new System.Drawing.Point(65, 572);
this.lblPointDuration.Name = "lblPointDuration";
this.lblPointDuration.Size = new System.Drawing.Size(58, 13);
this.lblPointDuration.TabIndex = 7;
this.lblPointDuration.Text = "Time (ms): ";
//
// dgdPointList
//
this.dgdPointList.AllowUserToAddRows = false;
this.dgdPointList.AllowUserToResizeColumns = false;
this.dgdPointList.AllowUserToResizeRows = false;
this.dgdPointList.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgdPointList.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.colPoint,
this.colVoltage,
this.colDuration});
this.dgdPointList.Location = new System.Drawing.Point(710, 28);
this.dgdPointList.MultiSelect = false;
this.dgdPointList.Name = "dgdPointList";
this.dgdPointList.RowHeadersVisible = false;
this.dgdPointList.ScrollBars = System.Windows.Forms.ScrollBars.None;
this.dgdPointList.Size = new System.Drawing.Size(172, 528);
this.dgdPointList.TabIndex = 8;
//
// colPoint
//
this.colPoint.HeaderText = "Point";
this.colPoint.Name = "colPoint";
this.colPoint.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.colPoint.Width = 56;
//
// colVoltage
//
this.colVoltage.HeaderText = "Voltage";
this.colVoltage.Name = "colVoltage";
this.colVoltage.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.colVoltage.Width = 56;
//
// colDuration
//
this.colDuration.HeaderText = "Duration";
this.colDuration.Name = "colDuration";
this.colDuration.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.colDuration.Width = 56;
//
// btnRemovePoint
//
this.btnRemovePoint.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
this.btnRemovePoint.Location = new System.Drawing.Point(799, 562);
this.btnRemovePoint.Name = "btnRemovePoint";
this.btnRemovePoint.Size = new System.Drawing.Size(83, 23);
this.btnRemovePoint.TabIndex = 9;
this.btnRemovePoint.Text = "Remove Point";
this.btnRemovePoint.UseVisualStyleBackColor = true;
//
// btnAddPoint
//
this.btnAddPoint.Location = new System.Drawing.Point(710, 562);
this.btnAddPoint.Name = "btnAddPoint";
this.btnAddPoint.Size = new System.Drawing.Size(83, 23);
this.btnAddPoint.TabIndex = 10;
this.btnAddPoint.Text = "Add Point";
this.btnAddPoint.UseVisualStyleBackColor = true;
this.btnAddPoint.Click += new System.EventHandler(this.btnAddPoint_Click);
//
// chWaveform
//
this.chWaveform.BackColor = System.Drawing.SystemColors.Control;
this.chWaveform.BorderlineColor = System.Drawing.SystemColors.WindowText;
chartArea1.Area3DStyle.LightStyle = System.Windows.Forms.DataVisualization.Charting.LightStyle.Realistic;
chartArea1.AxisX.MajorGrid.Interval = 1000D;
chartArea1.AxisX.MajorGrid.LineColor = System.Drawing.Color.LightGray;
chartArea1.AxisX.MajorTickMark.Interval = 1000D;
chartArea1.AxisX.Maximum = 5000D;
chartArea1.AxisX.Minimum = 0D;
chartArea1.AxisX.MinorGrid.Enabled = true;
chartArea1.AxisX.MinorGrid.Interval = 100D;
chartArea1.AxisX.MinorGrid.LineColor = System.Drawing.Color.WhiteSmoke;
chartArea1.AxisX.Title = "Time (seconds)";
chartArea1.AxisX2.IsStartedFromZero = false;
chartArea1.AxisY.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount;
chartArea1.AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
chartArea1.AxisY.MajorGrid.LineColor = System.Drawing.Color.LightGray;
chartArea1.AxisY.MajorTickMark.Interval = 1D;
chartArea1.AxisY.MajorTickMark.IntervalOffset = 0D;
chartArea1.AxisY.MajorTickMark.IntervalOffsetType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Auto;
chartArea1.AxisY.MajorTickMark.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
chartArea1.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.AcrossAxis;
chartArea1.AxisY.Maximum = 16D;
chartArea1.AxisY.Minimum = 0D;
chartArea1.AxisY.MinorGrid.Enabled = true;
chartArea1.AxisY.MinorGrid.Interval = 0.25D;
chartArea1.AxisY.MinorGrid.LineColor = System.Drawing.Color.WhiteSmoke;
chartArea1.AxisY.MinorTickMark.Enabled = true;
chartArea1.AxisY.MinorTickMark.Interval = 0.25D;
chartArea1.AxisY.MinorTickMark.Size = 0.25F;
chartArea1.AxisY.MinorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.AcrossAxis;
chartArea1.AxisY.Title = "Voltage";
chartArea1.Name = "ChartArea1";
this.chWaveform.ChartAreas.Add(chartArea1);
legend1.Enabled = false;
legend1.Name = "Legend1";
this.chWaveform.Legends.Add(legend1);
this.chWaveform.Location = new System.Drawing.Point(13, 28);
this.chWaveform.Name = "chWaveform";
this.chWaveform.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.Excel;
series1.ChartArea = "ChartArea1";
series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StepLine;
series1.Legend = "Legend1";
series1.Name = "Series1";
this.chWaveform.Series.Add(series1);
this.chWaveform.Size = new System.Drawing.Size(691, 528);
this.chWaveform.TabIndex = 5;
this.chWaveform.Click += new System.EventHandler(this.chWaveform_Click);
//
// WaveformMaker
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(894, 594);
this.Controls.Add(this.btnAddPoint);
this.Controls.Add(this.btnRemovePoint);
this.Controls.Add(this.dgdPointList);
this.Controls.Add(this.lblPointDuration);
this.Controls.Add(this.lblPointVoltage);
this.Controls.Add(this.chWaveform);
this.Controls.Add(this.btnRun);
this.Controls.Add(this.mnuStrip);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "WaveformMaker";
this.Text = "Waveform Maker";
this.Load += new System.EventHandler(this.WaveformMaker_Load);
this.mnuStrip.ResumeLayout(false);
this.mnuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dgdPointList)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.chWaveform)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.MenuStrip mnuStrip;
private System.Windows.Forms.ToolStripMenuItem mnuFile;
private System.Windows.Forms.ToolStripMenuItem mnuFileSaveWaveform;
private System.Windows.Forms.ToolStripMenuItem mnuFileExit;
private System.Windows.Forms.Button btnRun;
private System.Windows.Forms.Label lblPointVoltage;
private System.Windows.Forms.Label lblPointDuration;
private System.Windows.Forms.DataGridView dgdPointList;
private System.Windows.Forms.DataGridViewTextBoxColumn colPoint;
private System.Windows.Forms.DataGridViewTextBoxColumn colVoltage;
private System.Windows.Forms.DataGridViewTextBoxColumn colDuration;
private System.Windows.Forms.Button btnRemovePoint;
private System.Windows.Forms.Button btnAddPoint;
private System.Windows.Forms.DataVisualization.Charting.Chart chWaveform;
}
}
Your code works fine but you need to add a DataPoint to trigger the Chart's display.
This is most likely because without any data the automatic settings, which are default for most elements, including ChartArea's Size, have nothing to work from. I tried it and after adding even a dummy point the grid and all other nice details will show just fine..:
As you can see clearing the DataPoints will wipe out the chart again..
If you want your Series clean of dummy data you can either delete the dummy after adding the first data or add a dummy series..

Error: variable not declared in GUI design file

Newbie question. I downloaded the source of a project written in C#. There is an error occurring in one of the designer files used for constructing the GUI. Source attached below:
namespace Neurotec.Samples
{
partial class MainForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPageEnrollFromFile = new System.Windows.Forms.TabPage();
this.enrollFromFilePanel = new Neurotec.Samples.EnrollFromFile();
this.tabPageEnrollFromMicrophone = new System.Windows.Forms.TabPage();
this.enrollFromMicrophonePanel = new Neurotec.Samples.EnrollFromMicrophone();
this.tabPageVerify = new System.Windows.Forms.TabPage();
this.verifyVoicePanel = new Neurotec.Samples.VerifyVoice();
this.tabPageIdentify = new System.Windows.Forms.TabPage();
this.identifyVoicePanel = new Neurotec.Samples.IdentifyVoice();
this.tabControl1.SuspendLayout();
this.tabPageEnrollFromFile.SuspendLayout();
this.tabPageEnrollFromMicrophone.SuspendLayout();
this.tabPageVerify.SuspendLayout();
this.tabPageIdentify.SuspendLayout();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPageEnrollFromFile);
this.tabControl1.Controls.Add(this.tabPageEnrollFromMicrophone);
this.tabControl1.Controls.Add(this.tabPageVerify);
this.tabControl1.Controls.Add(this.tabPageIdentify);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(551, 398);
this.tabControl1.TabIndex = 0;
this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.TabControlSelectedIndexChanged);
//
// enrollFromFilePanel
//
this.enrollFromFilePanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.enrollFromFilePanel.Location = new System.Drawing.Point(3, 3);
this.enrollFromFilePanel.Name = "enrollFromFilePanel";
this.enrollFromFilePanel.Size = new System.Drawing.Size(540, 316);
this.enrollFromFilePanel.TabIndex = 0;
//
// tabPageEnrollFromFile
//
this.tabPageEnrollFromFile.Controls.Add(this.enrollFromFilePanel);
this.tabPageEnrollFromFile.Location = new System.Drawing.Point(4, 22);
this.tabPageEnrollFromFile.Name = "tabPageEnrollFromFile";
this.tabPageEnrollFromFile.Padding = new System.Windows.Forms.Padding(3);
this.tabPageEnrollFromFile.Size = new System.Drawing.Size(546, 322);
this.tabPageEnrollFromFile.TabIndex = 0;
this.tabPageEnrollFromFile.Text = "Enroll From File";
this.tabPageEnrollFromFile.UseVisualStyleBackColor = true;
//
// tabPageEnrollFromMicrophone
//
this.tabPageEnrollFromMicrophone.Controls.Add(this.enrollFromMicrophonePanel);
this.tabPageEnrollFromMicrophone.Location = new System.Drawing.Point(4, 22);
this.tabPageEnrollFromMicrophone.Name = "tabPageEnrollFromMicrophone";
this.tabPageEnrollFromMicrophone.Padding = new System.Windows.Forms.Padding(3);
this.tabPageEnrollFromMicrophone.Size = new System.Drawing.Size(546, 322);
this.tabPageEnrollFromMicrophone.TabIndex = 1;
this.tabPageEnrollFromMicrophone.Text = "Enroll From Microphone";
this.tabPageEnrollFromMicrophone.UseVisualStyleBackColor = true;
//
// enrollFromMicrophonePanel
//
this.enrollFromMicrophonePanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.enrollFromMicrophonePanel.Location = new System.Drawing.Point(3, 3);
this.enrollFromMicrophonePanel.Name = "enrollFromMicrophonePanel";
this.enrollFromMicrophonePanel.Size = new System.Drawing.Size(540, 316);
this.enrollFromMicrophonePanel.TabIndex = 0;
//
// tabPageVerify
//
this.tabPageVerify.Controls.Add(this.verifyVoicePanel);
this.tabPageVerify.Location = new System.Drawing.Point(4, 22);
this.tabPageVerify.Name = "tabPageVerify";
this.tabPageVerify.Size = new System.Drawing.Size(546, 322);
this.tabPageVerify.TabIndex = 2;
this.tabPageVerify.Text = "Verify Voice";
this.tabPageVerify.UseVisualStyleBackColor = true;
//
// verifyVoicePanel
//
this.verifyVoicePanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.verifyVoicePanel.Location = new System.Drawing.Point(0, 0);
this.verifyVoicePanel.Name = "verifyVoicePanel";
this.verifyVoicePanel.Size = new System.Drawing.Size(546, 322);
this.verifyVoicePanel.TabIndex = 0;
//
// tabPageIdentify
//
this.tabPageIdentify.Controls.Add(this.identifyVoicePanel);
this.tabPageIdentify.Location = new System.Drawing.Point(4, 22);
this.tabPageIdentify.Name = "tabPageIdentify";
this.tabPageIdentify.Size = new System.Drawing.Size(543, 372);
this.tabPageIdentify.TabIndex = 3;
this.tabPageIdentify.Text = "Identify Voice";
this.tabPageIdentify.UseVisualStyleBackColor = true;
//
// identifyVoicePanel
//
this.identifyVoicePanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.identifyVoicePanel.Location = new System.Drawing.Point(0, 0);
this.identifyVoicePanel.Name = "identifyVoicePanel";
this.identifyVoicePanel.Size = new System.Drawing.Size(543, 372);
this.identifyVoicePanel.TabIndex = 0;
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(551, 398);
this.Controls.Add(this.tabControl1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "MainForm";
this.Text = "Simple Voices Sample";
this.Load += new System.EventHandler(this.MainFormLoad);
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainFormFormClosing);
this.tabControl1.ResumeLayout(false);
this.tabPageEnrollFromFile.ResumeLayout(false);
this.tabPageEnrollFromMicrophone.ResumeLayout(false);
this.tabPageVerify.ResumeLayout(false);
this.tabPageIdentify.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPageEnrollFromFile;
private System.Windows.Forms.TabPage tabPageEnrollFromMicrophone;
private System.Windows.Forms.TabPage tabPageVerify;
private System.Windows.Forms.TabPage tabPageIdentify;
private EnrollFromFile enrollFromFilePanel;
private EnrollFromMicrophone enrollFromMicrophonePanel;
private VerifyVoice verifyVoicePanel;
private IdentifyVoice identifyVoicePanel;
}
}
The errors state that some variables were undeclared or unassigned. As an example, the variable "enrollFromFilePanel" is said to be undeclared but it was created with the line "private EnrollFromFile enrollFromFilePanel;". I am sorry that I cannot provide an sscce and I hope that the solution is something simple. Thank you.

C# WinForms - how to send updates from DataGridView to DataBase

I have a .mdb file with a Customers table and an Agents table. The only thing that the Agents table does as yet is populate the Agent dropdown for each customer...
I have a DataGridView linked to the customerBindingSource. The customerBindingSource has DataMember set to Customer and DataSource set to bindingSource1. This has the DataSource set to customerAppDS21. If I select customerAppDS21 and click Edit in DataSet Designer I can quite clearly see that there is a Customer table and Agent table. These were dragged directly from the Data.mdf > Tables folder. I have been through the Configure wizard and checked that the Update, Insert and Delete commands are generated correctly.
I am setting the unique ID (GUID) when the user leaves a row or adds a row (I dont think both are needed, but I very much doubt this is the cause of the problem). The user can update or add as many rows as possible. When the user clicks the Save button it calls customerTableAdapter.Update(customerAppDS21.Customer);. All the events are definitely wired up correctly.
The problem is basically that the DataSet appears to get updated but the database itself is not updated. I can close the program and reload it straight away and the data is there. However if I make any changes to the code and then recompile and load the program all the data is gone. This is what makes me think the DataSet is being updated but not the database.
Does anyone have any idea how to solve the problem? I have tried adding the .acceptChanges(); line both before and after the .Update(bla); line, with no success. I have also tried calling customerBindingSource.EndEdit(); and bindingSource1.EndEdit(); before the .Update(bla); line.
Any help with this would be greatly appreciated. I have had this problem for 2 days now and tried alsorts of tutorials to get a hint on where I am going wrong.
Regards,
Richard
Update: Code below...
void button1_Click(object sender, EventArgs e)
{
Validate();
customerBindingSource.EndEdit();
customerTableAdapter.Update(customerAppDS21.Customer);
}
void grdCustomers_RowLeave(object sender, DataGridViewCellEventArgs e)
{
DataGridViewRow gvr = grdCustomers.Rows[e.RowIndex];
if (gvr.Cells[0].Value == null)
{
String g = Guid.NewGuid().ToString();
gvr.Cells[0].Value = g;
}
else
{
String currID = gvr.Cells[0].Value.ToString();
if (currID.Equals(""))
{
String g = Guid.NewGuid().ToString();
gvr.Cells[0].Value = g;
}
}
}
void grdCustomers_UserAddedRow(object sender, DataGridViewRowEventArgs e)
{
DataGridViewRow gvr = grdCustomers.Rows[grdCustomers.SelectedCells[0].RowIndex];
if (gvr.Cells[0].Value == null)
{
String g = Guid.NewGuid().ToString();
gvr.Cells[0].Value = g;
}
else
{
String currID = gvr.Cells[0].Value.ToString();
if (currID.Equals(""))
{
String g = Guid.NewGuid().ToString();
gvr.Cells[0].Value = g;
}
}
}
Designer code (sorry its so long - I dont want to risk missing out anything vital):
namespace CustomerApp
{
partial class CustomerAppForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.button1 = new System.Windows.Forms.Button();
this.grdCustomers = new System.Windows.Forms.DataGridView();
this.agentBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.bindingSource1 = new System.Windows.Forms.BindingSource(this.components);
this.customerAppDS21 = new CustomerApp.CustomerAppDS2();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.customerTableAdapter = new CustomerApp.CustomerAppDS2TableAdapters.CustomerTableAdapter();
this.agentTableAdapter = new CustomerApp.CustomerAppDS2TableAdapters.AgentTableAdapter();
this.customerBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.idDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.companynameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.contactforenameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.contactsurnameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.companyaddress1DataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.companyaddress2DataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.companytownDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.companycountyDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.companypostcodeDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.contacttelephoneDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.contactfaxDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.contactemailDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.agentIDDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
this.contactfullnameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.grdCustomers)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.agentBindingSource)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.customerAppDS21)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.customerBindingSource)).BeginInit();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Location = new System.Drawing.Point(12, 12);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(1000, 640);
this.tabControl1.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.button1);
this.tabPage1.Controls.Add(this.grdCustomers);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(992, 614);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "Customers";
this.tabPage1.UseVisualStyleBackColor = true;
//
// button1
//
this.button1.Location = new System.Drawing.Point(882, 462);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "Save";
this.button1.UseVisualStyleBackColor = true;
//
// grdCustomers
//
this.grdCustomers.AllowUserToOrderColumns = true;
this.grdCustomers.AutoGenerateColumns = false;
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.grdCustomers.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
this.grdCustomers.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.grdCustomers.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.idDataGridViewTextBoxColumn,
this.companynameDataGridViewTextBoxColumn,
this.contactforenameDataGridViewTextBoxColumn,
this.contactsurnameDataGridViewTextBoxColumn,
this.companyaddress1DataGridViewTextBoxColumn,
this.companyaddress2DataGridViewTextBoxColumn,
this.companytownDataGridViewTextBoxColumn,
this.companycountyDataGridViewTextBoxColumn,
this.companypostcodeDataGridViewTextBoxColumn,
this.contacttelephoneDataGridViewTextBoxColumn,
this.contactfaxDataGridViewTextBoxColumn,
this.contactemailDataGridViewTextBoxColumn,
this.agentIDDataGridViewTextBoxColumn,
this.contactfullnameDataGridViewTextBoxColumn});
this.grdCustomers.DataSource = this.customerBindingSource;
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.grdCustomers.DefaultCellStyle = dataGridViewCellStyle2;
this.grdCustomers.Location = new System.Drawing.Point(3, 3);
this.grdCustomers.Name = "grdCustomers";
dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.grdCustomers.RowHeadersDefaultCellStyle = dataGridViewCellStyle3;
this.grdCustomers.RowTemplate.DefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
this.grdCustomers.RowTemplate.DefaultCellStyle.Padding = new System.Windows.Forms.Padding(2);
this.grdCustomers.RowTemplate.DefaultCellStyle.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(224)))), ((int)(((byte)(192)))));
this.grdCustomers.Size = new System.Drawing.Size(983, 605);
this.grdCustomers.TabIndex = 0;
//
// agentBindingSource
//
this.agentBindingSource.DataMember = "Agent";
this.agentBindingSource.DataSource = this.bindingSource1;
//
// bindingSource1
//
this.bindingSource1.AllowNew = true;
this.bindingSource1.DataSource = this.customerAppDS21;
this.bindingSource1.Position = 0;
//
// customerAppDS21
//
this.customerAppDS21.DataSetName = "CustomerAppDS2";
this.customerAppDS21.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
//
// tabPage2
//
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
this.tabPage2.Size = new System.Drawing.Size(992, 614);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "Agents";
this.tabPage2.UseVisualStyleBackColor = true;
//
// customerTableAdapter
//
this.customerTableAdapter.ClearBeforeFill = true;
//
// agentTableAdapter
//
this.agentTableAdapter.ClearBeforeFill = true;
//
// customerBindingSource
//
this.customerBindingSource.DataMember = "Customer";
this.customerBindingSource.DataSource = this.bindingSource1;
//
// idDataGridViewTextBoxColumn
//
this.idDataGridViewTextBoxColumn.DataPropertyName = "id";
this.idDataGridViewTextBoxColumn.HeaderText = "id";
this.idDataGridViewTextBoxColumn.Name = "idDataGridViewTextBoxColumn";
this.idDataGridViewTextBoxColumn.ReadOnly = true;
//
// companynameDataGridViewTextBoxColumn
//
this.companynameDataGridViewTextBoxColumn.DataPropertyName = "company_name";
this.companynameDataGridViewTextBoxColumn.HeaderText = "Company Name";
this.companynameDataGridViewTextBoxColumn.Name = "companynameDataGridViewTextBoxColumn";
this.companynameDataGridViewTextBoxColumn.ToolTipText = "The name of the company";
//
// contactforenameDataGridViewTextBoxColumn
//
this.contactforenameDataGridViewTextBoxColumn.DataPropertyName = "contact_forename";
this.contactforenameDataGridViewTextBoxColumn.HeaderText = "Contact Forename";
this.contactforenameDataGridViewTextBoxColumn.Name = "contactforenameDataGridViewTextBoxColumn";
//
// contactsurnameDataGridViewTextBoxColumn
//
this.contactsurnameDataGridViewTextBoxColumn.DataPropertyName = "contact_surname";
this.contactsurnameDataGridViewTextBoxColumn.HeaderText = "Contact Surname";
this.contactsurnameDataGridViewTextBoxColumn.Name = "contactsurnameDataGridViewTextBoxColumn";
//
// companyaddress1DataGridViewTextBoxColumn
//
this.companyaddress1DataGridViewTextBoxColumn.DataPropertyName = "company_address1";
this.companyaddress1DataGridViewTextBoxColumn.HeaderText = "Address 1";
this.companyaddress1DataGridViewTextBoxColumn.Name = "companyaddress1DataGridViewTextBoxColumn";
//
// companyaddress2DataGridViewTextBoxColumn
//
this.companyaddress2DataGridViewTextBoxColumn.DataPropertyName = "company_address2";
this.companyaddress2DataGridViewTextBoxColumn.HeaderText = "Address 2";
this.companyaddress2DataGridViewTextBoxColumn.Name = "companyaddress2DataGridViewTextBoxColumn";
//
// companytownDataGridViewTextBoxColumn
//
this.companytownDataGridViewTextBoxColumn.DataPropertyName = "company_town";
this.companytownDataGridViewTextBoxColumn.HeaderText = "Town";
this.companytownDataGridViewTextBoxColumn.Name = "companytownDataGridViewTextBoxColumn";
//
// companycountyDataGridViewTextBoxColumn
//
this.companycountyDataGridViewTextBoxColumn.DataPropertyName = "company_county";
this.companycountyDataGridViewTextBoxColumn.HeaderText = "County";
this.companycountyDataGridViewTextBoxColumn.Name = "companycountyDataGridViewTextBoxColumn";
//
// companypostcodeDataGridViewTextBoxColumn
//
this.companypostcodeDataGridViewTextBoxColumn.DataPropertyName = "company_postcode";
this.companypostcodeDataGridViewTextBoxColumn.HeaderText = "Postcode";
this.companypostcodeDataGridViewTextBoxColumn.Name = "companypostcodeDataGridViewTextBoxColumn";
//
// contacttelephoneDataGridViewTextBoxColumn
//
this.contacttelephoneDataGridViewTextBoxColumn.DataPropertyName = "contact_telephone";
this.contacttelephoneDataGridViewTextBoxColumn.HeaderText = "Telephone";
this.contacttelephoneDataGridViewTextBoxColumn.Name = "contacttelephoneDataGridViewTextBoxColumn";
//
// contactfaxDataGridViewTextBoxColumn
//
this.contactfaxDataGridViewTextBoxColumn.DataPropertyName = "contact_fax";
this.contactfaxDataGridViewTextBoxColumn.HeaderText = "Fax";
this.contactfaxDataGridViewTextBoxColumn.Name = "contactfaxDataGridViewTextBoxColumn";
//
// contactemailDataGridViewTextBoxColumn
//
this.contactemailDataGridViewTextBoxColumn.DataPropertyName = "contact_email";
this.contactemailDataGridViewTextBoxColumn.HeaderText = "Email";
this.contactemailDataGridViewTextBoxColumn.Name = "contactemailDataGridViewTextBoxColumn";
//
// agentIDDataGridViewTextBoxColumn
//
this.agentIDDataGridViewTextBoxColumn.DataPropertyName = "agentID";
this.agentIDDataGridViewTextBoxColumn.DataSource = this.agentBindingSource;
this.agentIDDataGridViewTextBoxColumn.DisplayMember = "contact_fullname";
this.agentIDDataGridViewTextBoxColumn.HeaderText = "agentID";
this.agentIDDataGridViewTextBoxColumn.Name = "agentIDDataGridViewTextBoxColumn";
this.agentIDDataGridViewTextBoxColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
this.agentIDDataGridViewTextBoxColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
this.agentIDDataGridViewTextBoxColumn.ValueMember = "id";
//
// contactfullnameDataGridViewTextBoxColumn
//
this.contactfullnameDataGridViewTextBoxColumn.DataPropertyName = "contact_fullname";
this.contactfullnameDataGridViewTextBoxColumn.HeaderText = "contact_fullname";
this.contactfullnameDataGridViewTextBoxColumn.Name = "contactfullnameDataGridViewTextBoxColumn";
this.contactfullnameDataGridViewTextBoxColumn.ReadOnly = true;
this.contactfullnameDataGridViewTextBoxColumn.Visible = false;
//
// CustomerAppForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1184, 662);
this.Controls.Add(this.tabControl1);
this.Location = new System.Drawing.Point(100, 100);
this.Name = "CustomerAppForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Heritage Art Papers Ltd - Customer Application";
this.Load += new System.EventHandler(this.CustomerAppForm_Load);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.grdCustomers)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.agentBindingSource)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.customerAppDS21)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.customerBindingSource)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.BindingSource bindingSource1;
private CustomerAppDS2 customerAppDS21;
private System.Windows.Forms.BindingSource agentBindingSource;
private CustomerAppDS2TableAdapters.CustomerTableAdapter customerTableAdapter;
private CustomerAppDS2TableAdapters.AgentTableAdapter agentTableAdapter;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.BindingSource customerBindingSource;
private System.Windows.Forms.DataGridViewTextBoxColumn idDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn companynameDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn contactforenameDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn contactsurnameDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn companyaddress1DataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn companyaddress2DataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn companytownDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn companycountyDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn companypostcodeDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn contacttelephoneDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn contactfaxDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn contactemailDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewComboBoxColumn agentIDDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn contactfullnameDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridView grdCustomers;
}
}
I guess this might be your problem. Read these two articles very carefully. The first one contains a thread where in the second link (I gave below) is suggested.
http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.adonet/topic58794.aspx
and
http://msdn.microsoft.com/en-us/library/ms246989.aspx
In the first link, read the answer of: Kerry Moorman.
I guess these links might help:
http://msdn.microsoft.com/en-us/library/xzb1zw3x%28VS.80%29.aspx
and
http://www.c-sharpcorner.com/UploadFile/Ashish1/dataset02052006180740PM/dataset.aspx

Categories

Resources