7 Replies - 2857 Views - Last Post: 22 May 2010 - 02:27 PM Rate Topic: -----

#1 jamalb88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 11-May 10

Unwanted columns in datagrid( C# & LINQ)

Posted 21 May 2010 - 02:50 PM

I have problem with my dataGrid which contain Unwanted columns I don't know how it came!

As you can see here before deuging:

Posted Image

And here when deguging:

Posted Image

The code for this form is:

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 OutChequeSystemApp.lib;
using DevComponents.DotNetBar;

namespace OutChequeSystemApp.Controls
{
    public partial class IncomingInboxForm : Office2007Form
    {
        public IncomingInboxForm()
        {
            InitializeComponent();
        }

        public void SetCheques(Cheque[] Cheques)
        {
            try
            {
                GRDIncomingInboxGrid.DataSource = Cheques;
            }
            catch (Exception s)
            {

            }
        }
          
        private void GRDIncomingInboxGrid_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int ChequeID = int.Parse(GRDIncomingInboxGrid.Rows[e.RowIndex].Cells[0].Value.ToString());

                OutChequeSystemDataContext context = new OutChequeSystemDataContext(Connection.OpenConnection());

                var Query = from p in context.Cheques
                            where p.ChequeID == ChequeID
                            select p;

                Cheque SelectedCheque = Query.Single();


                EditChequeForm newEditChequeForm = new EditChequeForm();
                newEditChequeForm.MdiParent = this.MdiParent;
                newEditChequeForm.SetCheque(SelectedCheque);

                newEditChequeForm.Show();
            }
            catch (Exception s)
            {

            }

        }
        private void IncomingInboxForm_Load(object sender, EventArgs e)
        {
            //Disable Generating Data Grid Columns

            GRDIncomingInboxGrid.AutoGenerateColumns = false;
        }

        private void CloseButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}




And here is my ERD:

Posted Image

Can you help me with this? :(

JB

Is This A Good Question/Topic? 0
  • +

Replies To: Unwanted columns in datagrid( C# & LINQ)

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Unwanted columns in datagrid( C# & LINQ)

Posted 21 May 2010 - 08:51 PM

You don't describe the Cheque object or where it is set (where is the call to public void SetCheques(Cheque[] Cheques) ?)

This post has been edited by Momerath: 21 May 2010 - 08:52 PM

Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: Unwanted columns in datagrid( C# & LINQ)

Posted 21 May 2010 - 09:03 PM

You most likely still have the AutogenerateColumns property for the grid set to TRUE. You will want to make that FALSE.
Was This Post Helpful? 1
  • +
  • -

#4 jamalb88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 11-May 10

Re: Unwanted columns in datagrid( C# & LINQ)

Posted 22 May 2010 - 02:09 AM

View PostMomerath, on 21 May 2010 - 07:51 PM, said:

You don't describe the Cheque object or where it is set (where is the call to public void SetCheques(Cheque[] Cheques) ?)



mmm in this form the cheques requested then the request go to the chosen employee inbox

Posted Image

here is the code:

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 OutChequeSystemApp.lib;
using DevComponents.DotNetBar;

namespace OutChequeSystemApp.Controls
{
    public partial class AddNewChequeForm : Office2007Form
    {
        public AddNewChequeForm()
        {
            InitializeComponent();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void AddNewChequeForm_Load(object sender, EventArgs e)
        {
            try
            {
                int CurrentRequestNumber = CheckRequestNumber();

                if (CurrentRequestNumber == -1) TxtRequestNumberText.Text = "1";
                else TxtRequestNumberText.Text = CurrentRequestNumber.ToString();

                LoadEmployees();
                LoadBanks();
            }
            catch (Exception s)
            {

            }
        }

        int CheckRequestNumber()
        {
            try
            {
                OutChequeSystemDataContext context = new OutChequeSystemDataContext(Connection.OpenConnection());

                var Query = from p in context.Cheques
                            select p;

                Cheque[] Cheques = Query.ToArray();

                if (Cheques.Count() <= 0) return 1;
                else
                {
                    return ((int.Parse(Cheques[Cheques.Length - 1].RequestNumber)) + 1);
                }

            }
            catch (Exception s)
            {
                return -1;
            }
        }

        void LoadEmployees()
        {
            try
            {
                OutChequeSystemDataContext context = new OutChequeSystemDataContext(Connection.OpenConnection());

                var Query = from p in context.Employees
                            select p;

                Employee[] CurrentEmployees = Query.ToArray();

                foreach (Employee CurrentEmployee in CurrentEmployees)
                {
                    ListBoxItem CurrentEmployeeItem = new ListBoxItem(String.Format("{0} {1}", CurrentEmployee.FirstName, CurrentEmployee.LastName), CurrentEmployee.EmployeeID.ToString());

                    CmboEmployeeList.Items.Add(CurrentEmployeeItem);
                }
            }
            catch (Exception s)
            {

            }
        }

        void LoadBanks()
        {
            try
            {
                OutChequeSystemDataContext context = new OutChequeSystemDataContext(Connection.OpenConnection());

                var Query = from p in context.CustomerBanks
                            select p;

                CustomerBank[] Banks = Query.ToArray();

                foreach (CustomerBank CurrentBank in Banks)
                {
                    ListBoxItem CurrentBankItem = new ListBoxItem(CurrentBank.BankName, CurrentBank.BankID.ToString());

                    cmboBankList.Items.Add(CurrentBankItem);
                }
            }
            catch (Exception s)
            {

            }
        }

        private void PckrHandleDateText_ValueChanged(object sender, EventArgs e)
        {

        }

        private void TxtChequeNumberText_TextChanged(object sender, EventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void CmboEmployeeList_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void CloseButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ClearButton_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure to clear all fields?", "Confirm clear", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                // a 'DialogResult.Yes' value was returned from the MessageBox
                // proceed  Clearing
                try
                {
                    TxtChequeNumberText.Clear();
                    TxtChequeHolderNameText.Clear();
                    TxtPaymentReasonText.Clear();
                    TxtChequeAmountInLetters.Clear();
                    TxtChequeAmountInNumbers.Clear();
                    TxtNotesText.Clear();
                    cmboBankList.SelectedItem = null;
                    CmboEmployeeList.SelectedItem = null;
                }
                catch (Exception s)
                {

                }
            }
        }

        private void RequestButton_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure to request this cheque?", "Confirm request", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                // a 'DialogResult.Yes' value was returned from the MessageBox
                // proceed  requsting
                try
                {
                    OutChequeSystemDataContext context = new OutChequeSystemDataContext(Connection.OpenConnection());

                    Cheque newCheque = new Cheque();
                    newCheque.ChequeID = int.Parse(TxtChequeNumberText.Text);
                    newCheque.ChequeAmountInLetters = TxtChequeAmountInLetters.Text;
                    newCheque.ChequeAmountInNumbers = decimal.Parse(TxtChequeAmountInNumbers.Text);
                    newCheque.ChequeDate = DateTime.Parse(PckrChequeDateText.Text);
                    newCheque.ChequeHolderName = TxtChequeHolderNameText.Text;
                    newCheque.BankID = int.Parse(((ListBoxItem)cmboBankList.SelectedItem).ItemValue);
                    newCheque.HandleDate = DateTime.Parse(PckrHandleDateText.Text);
                    newCheque.Notes = TxtNotesText.Text;
                    newCheque.PaymentReason = TxtPaymentReasonText.Text;
                    newCheque.RequestNumber = TxtRequestNumberText.Text;


                    //now add the current cheque to the cheques table
                    context.Cheques.Insertonsubmit(newCheque);

                    context.SubmitChanges();

                    //now insert a new cheque into the inbox of the current employee

                    ChequesInbox currentInbox = new ChequesInbox();

                    currentInbox.ApprovalDate = DateTime.Now;
                    currentInbox.Cheque = newCheque;
                    currentInbox.ChequeStatusID = 1;
                    currentInbox.EmployeeID = int.Parse(((ListBoxItem)CmboEmployeeList.SelectedItem).ItemValue);
                    currentInbox.isApproved = false;
                    currentInbox.Notes = TxtNotesText.Text;


                    context.ChequesInboxes.Insertonsubmit(currentInbox);

                    context.SubmitChanges();

                    MessageBox.Show("Cheque is created successfully", "Notification Message", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                catch (Exception s)
                {
                    MessageBox.Show(s.Message, "Notification Message", MessageBoxButtons.OK);
                }
            }
        }
    }
}




I hope this what you asked. Sorry if I didn't understand you right because I'm not professional in programming and my English is not perfect.

waiting for your respond

View Posteclipsed4utoo, on 21 May 2010 - 08:03 PM, said:

You most likely still have the AutogenerateColumns property for the grid set to TRUE. You will want to make that FALSE.


If you checked the coode you will see that:


GRDIncomingInboxGrid.AutoGenerateColumns = false;


So that is why this driving me crazy, I didn't know why it keeps generating the columns :(
Was This Post Helpful? 0
  • +
  • -

#5 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Unwanted columns in datagrid( C# & LINQ)

Posted 22 May 2010 - 06:03 AM

Put a breakpoint on this line
GRDIncomingInboxGrid.DataSource = Cheques;
and check the autogenerate value at that point. I suspect it isn't what you think it is.

Also, why don't you set the autogenerate to false in the properties window of the control?

This post has been edited by Momerath: 22 May 2010 - 06:06 AM

Was This Post Helpful? 0
  • +
  • -

#6 jamalb88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 11-May 10

Re: Unwanted columns in datagrid( C# & LINQ)

Posted 22 May 2010 - 10:54 AM

Thank you for your reply

I did insert a break point as you told me and I kept presing F11 I don't know if these print screens will help:

Posted Image

as you can see it jumped to the main form

Posted Image

Posted Image

Posted Image

as you can see here is the unwanted columns started

Posted Image

this is the part of the code in OutChequeSystem.designer.cs as shown in the picture above

		public Cheque()
		{
			this._EmployeesReportsHistories = new EntitySet<EmployeesReportsHistory>(new Action<EmployeesReportsHistory>(this.attach_EmployeesReportsHistories), new Action<EmployeesReportsHistory>(this.detach_EmployeesReportsHistories));
			this._ChequesInboxes = new EntitySet<ChequesInbox>(new Action<ChequesInbox>(this.attach_ChequesInboxes), new Action<ChequesInbox>(this.detach_ChequesInboxes));
			this._PaymentVouchers = new EntitySet<PaymentVoucher>(new Action<PaymentVoucher>(this.attach_PaymentVouchers), new Action<PaymentVoucher>(this.detach_PaymentVouchers));
			this._CustomerBank = default(EntityRef<CustomerBank>);
			OnCreated();
		}
		
		[Column(Storage="_ChequeID", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true)]
		public int ChequeID
		{
			get
			{
				return this._ChequeID;
			}
			set
			{
				if ((this._ChequeID != value))
				{
					this.OnChequeIDChanging(value);
					this.SendPropertyChanging();
					this._ChequeID = value;
					this.SendPropertyChanged("ChequeID");
					this.OnChequeIDChanged();
				}
			}
		}
		
		[Column(Storage="_RequestNumber", DbType="NVarChar(300) NOT NULL", CanBeNull=false)]
		public string RequestNumber
		{
			get
			{
				return this._RequestNumber;
			}
			set
			{
				if ((this._RequestNumber != value))
				{
					this.OnRequestNumberChanging(value);
					this.SendPropertyChanging();
					this._RequestNumber = value;
					this.SendPropertyChanged("RequestNumber");
					this.OnRequestNumberChanged();
				}
			}
		}
		
		[Column(Storage="_ChequeHolderName", DbType="NVarChar(500) NOT NULL", CanBeNull=false)]
		public string ChequeHolderName
		{
			get
			{
				return this._ChequeHolderName;
			}
			set
			{
				if ((this._ChequeHolderName != value))
				{
					this.OnChequeHolderNameChanging(value);
					this.SendPropertyChanging();
					this._ChequeHolderName = value;
					this.SendPropertyChanged("ChequeHolderName");
					this.OnChequeHolderNameChanged();
				}
			}
		}
		
		[Column(Storage="_ChequeDate", DbType="DateTime NOT NULL")]
		public System.DateTime ChequeDate
		{
			get
			{
				return this._ChequeDate;
			}
			set
			{
				if ((this._ChequeDate != value))
				{
					this.OnChequeDateChanging(value);
					this.SendPropertyChanging();
					this._ChequeDate = value;
					this.SendPropertyChanged("ChequeDate");
					this.OnChequeDateChanged();
				}
			}
		}
		
		[Column(Storage="_BankID", DbType="Int NOT NULL")]
		public int BankID
		{
			get
			{
				return this._BankID;
			}
			set
			{
				if ((this._BankID != value))
				{
					if (this._CustomerBank.HasLoadedOrAssignedValue)
					{
						throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
					}
					this.OnBankIDChanging(value);
					this.SendPropertyChanging();
					this._BankID = value;
					this.SendPropertyChanged("BankID");
					this.OnBankIDChanged();
				}
			}
		}
		
		[Column(Storage="_ChequeAmountInNumbers", DbType="Money NOT NULL")]
		public decimal ChequeAmountInNumbers
		{
			get
			{
				return this._ChequeAmountInNumbers;
			}
			set
			{
				if ((this._ChequeAmountInNumbers != value))
				{
					this.OnChequeAmountInNumbersChanging(value);
					this.SendPropertyChanging();
					this._ChequeAmountInNumbers = value;
					this.SendPropertyChanged("ChequeAmountInNumbers");
					this.OnChequeAmountInNumbersChanged();
				}
			}
		}
		
		[Column(Storage="_ChequeAmountInLetters", DbType="NVarChar(500) NOT NULL", CanBeNull=false)]
		public string ChequeAmountInLetters
		{
			get
			{
				return this._ChequeAmountInLetters;
			}
			set
			{
				if ((this._ChequeAmountInLetters != value))
				{
					this.OnChequeAmountInLettersChanging(value);
					this.SendPropertyChanging();
					this._ChequeAmountInLetters = value;
					this.SendPropertyChanged("ChequeAmountInLetters");
					this.OnChequeAmountInLettersChanged();
				}
			}
		}
		
		[Column(Storage="_PaymentReason", DbType="NText", UpdateCheck=UpdateCheck.Never)]
		public string PaymentReason
		{
			get
			{
				return this._PaymentReason;
			}
			set
			{
				if ((this._PaymentReason != value))
				{
					this.OnPaymentReasonChanging(value);
					this.SendPropertyChanging();
					this._PaymentReason = value;
					this.SendPropertyChanged("PaymentReason");
					this.OnPaymentReasonchanged();
				}
			}
		}
		
		[Column(Storage="_HandleDate", DbType="DateTime NOT NULL")]
		public System.DateTime HandleDate
		{
			get
			{
				return this._HandleDate;
			}
			set
			{
				if ((this._HandleDate != value))
				{
					this.OnHandleDateChanging(value);
					this.SendPropertyChanging();
					this._HandleDate = value;
					this.SendPropertyChanged("HandleDate");
					this.OnHandleDateChanged();
				}
			}
		}
		
		[Column(Storage="_Notes", DbType="NText", UpdateCheck=UpdateCheck.Never)]
		public string Notes
		{
			get
			{
				return this._Notes;
			}
			set
			{
				if ((this._Notes != value))
				{
					this.OnNotesChanging(value);
					this.SendPropertyChanging();
					this._Notes = value;
					this.SendPropertyChanged("Notes");
					this.OnNotesChanged();
				}
			}
		}
		
		[Association(Name="Cheque_EmployeesReportsHistory", Storage="_EmployeesReportsHistories", ThisKey="ChequeID", OtherKey="ChequeID")]
		public EntitySet<EmployeesReportsHistory> EmployeesReportsHistories
		{
			get
			{
				return this._EmployeesReportsHistories;
			}
			set
			{
				this._EmployeesReportsHistories.Assign(value);
			}
		}
		
		[Association(Name="Cheque_ChequesInbox", Storage="_ChequesInboxes", ThisKey="ChequeID", OtherKey="ChequeID")]
		public EntitySet<ChequesInbox> ChequesInboxes
		{
			get
			{
				return this._ChequesInboxes;
			}
			set
			{
				this._ChequesInboxes.Assign(value);
			}
		}


and here is the code in the main form as shown in the picure

 private void linkLabel10_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                IncomingInboxForm newInbox = new IncomingInboxForm();
                newInbox.MdiParent = this;

                OutChequeSystemDataContext context = new OutChequeSystemDataContext(Connection.OpenConnection());

                

                var Query = from p in context.ChequesInboxes
                        where p.EmployeeID == MainFrm._CurrentEmployee.EmployeeID && p.isApproved == false
                        select p;

                List<Cheque> Cheques = new List<Cheque>();

                foreach (ChequesInbox inbox in Query.ToArray())
                {
                    Cheques.Add(inbox.Cheque);
                }

                newInbox.SetCheques(Cheques.ToArray());

                newInbox.Show();

               
            }
            catch (Exception s)
            {

            }
        }





=======

for the autogenerate to false in the properties window of the control I couldn't find it can you please tell me where exactly

Posted Image

I appreciate your corporate
Was This Post Helpful? 0
  • +
  • -

#7 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Unwanted columns in datagrid( C# & LINQ)

Posted 22 May 2010 - 11:05 AM

Sort Alphabetically (the AZ with the down arrow) and expand ApplicationSettings. Open PropertyBindings and add AutoGenerateColumns from the list.
Was This Post Helpful? 3
  • +
  • -

#8 jamalb88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 11-May 10

Re: Unwanted columns in datagrid( C# & LINQ)

Posted 22 May 2010 - 02:27 PM

Oh god!

It works!

Momerath I don't know how to thank you..

Thank you so much :^:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1