locked
strange datagrid problem RRS feed

  • Question

  • i have three columns in my datagrid: CATID,CATNAME and CATTYPE
    what is strange is that ONLY the FIRST row CATTYPE value does not show???????????? the value DOES exist in the database table

    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.Windows.Forms;
    using DevExpress.XtraGrid;
    using DevExpress.XtraEditors;
    
    namespace WinUI.Forms.BackOffice.MenuTabs.SystemTab.Accounting
    {
        using WinUI.BaseForms;
        using WinUI.DataSets;
        public partial class frmBalanceSheetCategories : frmButtons
        {
            public frmBalanceSheetCategories()
            {
                InitializeComponent();
            }
            string oldType;
            string oldDesc;
            bool typeChanged = false;
            bool descChanged = false;
            List<Account> lstAccounts = new List<Account>();
    
            public class Account
            {
                public Account(string acctid, string acctdesc)
                {
                    this.AcctId = acctid;
                    this.AcctDesc = acctdesc;
                }
                private string _AcctId = "";
    
                public string AcctId
                {
                    get { return _AcctId; }
                    set { _AcctId = value; }
                }
                private string _AcctDesc = string.Empty;
    
                public string AcctDesc
                {
                    get { return _AcctDesc; }
                    set { _AcctDesc = value; }
                }
            }
    
            private void frmBalanceSheetCategories_Load(object sender, EventArgs e)
            {
                // TODO: This line of code loads data into the 'bSCategoriesData.BALANCESHEET_CATEGORIES' table. You can move, or remove it, as needed.
                this.bALANCESHEET_CATEGORIESTableAdapter.Fill(this.bSCategoriesData.BALANCESHEET_CATEGORIES);
               
                lstAccounts.Add(new Account("1", "fixed assets"));
                lstAccounts.Add(new Account("2", "current assets"));
                lstAccounts.Add(new Account("3", "liabilities"));
                lookUpEdit1.Properties.DataSource = lstAccounts;
                lookUpEdit1.Properties.DisplayMember = "AcctDesc";
                lookUpEdit1.Properties.ValueMember = "AcctId";
                btnOk.Enabled = false;
                btnCancel.Enabled = false;
                textBox1.TextChanged += new EventHandler(textBox1_TextChanged);
                lookUpEdit1.TextChanged += new EventHandler(lookUpEdit1_TextChanged);
                textBox3.TextChanged += new EventHandler(textBox3_TextChanged);
            }
    
            private void btnInsert_Click(object sender, EventArgs e)
            {
                btnOk.Enabled = true;
               
                bALANCESHEETCATEGORIESBindingSource.AddNew();
                BSCategoriesData.BALANCESHEET_CATEGORIESRow newRow = (BSCategoriesData.BALANCESHEET_CATEGORIESRow)((DataRowView)this.bALANCESHEETCATEGORIESBindingSource.Current).Row;
                newRow.CATID = (int)bALANCESHEET_CATEGORIESTableAdapter.getMaxId();
                textBox2.Text = newRow.CATID.ToString();
                newRow.CATNAME = textBox3.Text.ToString();
                if (lookUpEdit1.EditValue != DBNull.Value) newRow.CATTYPE = lookUpEdit1.EditValue.ToString();
            }
    
            private void btnOk_Click(object sender, EventArgs e)
            {
                save();
                btnOk.Enabled = false;
                btnCancel.Enabled = false;
            }
    
            private void btnExit_Click(object sender, EventArgs e)
            {
                this.Close();
            }
    
            private void btnDelete_Click(object sender, EventArgs e)
            {
                //delete from datagrid and table
                DialogResult reply = MessageBox.Show("Sure to delete this entry", "Warning", MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
    
                if (reply == DialogResult.OK)
                {
                    bALANCESHEETCATEGORIESBindingSource.RemoveCurrent();
                    save();
                }
            }
    
            private void save()
            {
                bALANCESHEETCATEGORIESBindingSource.EndEdit();
                bALANCESHEET_CATEGORIESTableAdapter.Update(this.bSCategoriesData.BALANCESHEET_CATEGORIES);
            }
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
                if (textBox1.Text != string.Empty)
                {
                    this.bALANCESHEETCATEGORIESBindingSource.Filter = String.Format(" catname LIKE '%{0}%'", textBox1.Text);
                }
            }
    
            private void lookUpEdit1_TextChanged(object sender, EventArgs e)
            {
                System.Data.DataRow row = this.gridView1.GetDataRow(gridView1.FocusedRowHandle);
                if ((row[2].ToString() != lookUpEdit1.EditValue) && (lookUpEdit1.EditValue != DBNull.Value))
                {
                    row[2] = lookUpEdit1.EditValue;
                    btnOk.Enabled = true;
                    btnCancel.Enabled = true;
                    typeChanged = true;
                    oldType = row[2].ToString();
                }      
            }
    
            private void textBox3_TextChanged(object sender, EventArgs e)
            {
                System.Data.DataRow row = this.gridView1.GetDataRow(gridView1.FocusedRowHandle);
                string cellValue = row[1].ToString();
                oldDesc = cellValue;
                if (cellValue == textBox3.Text)
                {
                    btnOk.Enabled = false;
                    btnCancel.Enabled = false;
                }
                else
                {
                    btnOk.Enabled = true;
                    btnCancel.Enabled = true;
                    descChanged = true;
                }  
            }
    
            private void btnCancel_Click(object sender, EventArgs e)
            {
                if (typeChanged)
                {
                    lookUpEdit1.Text = lstAccounts.Where(account => account.AcctId.ToString() == oldType).First().AcctDesc;
                    //lookUpEdit1.EditValue = lstAccounts.Where(account => account.AcctId.ToString() == oldType).First().AcctDesc;
                    typeChanged = false;
                }
                if (descChanged)
                {
                    textBox3.Text = oldDesc;
                    descChanged = false;
                }
                btnCancel.Enabled = false;
                btnOk.Enabled = false;
            }
        }
    }
    my datagrid is bound to the balanceSheetCategoriesBindingSource...

    can any one help please?
    thanks
    • Moved by OmegaMan Tuesday, February 23, 2010 4:16 PM (From:Visual C# General)
    Tuesday, February 23, 2010 7:38 AM

All replies

  • This forum is for C# related question. It is unclear if this is a WPF or Winforms or ASP.Net related question. Please post any GUI related questions to the target forum:

    Windows Forms General
    Windows Presentation Foundation (WPF)
    ASP.Net forums

    depending on what you are working on.

    The C# forum is for C# related questions on the language constructs and not indirect component usage. THX

    William Wegerson (www.OmegaCoder.Com)
    Tuesday, February 23, 2010 4:16 PM
  • it is c# related.... somewhere in my code it nulls the first row's cattype value...
    none of my other datagrids is doing it, i tried to debug it but cannot find the problem
    Thursday, February 25, 2010 9:16 AM
  • it is c# related.... somewhere in my code it nulls the first row's cattype value...
    none of my other datagrids is doing it, i tried to debug it but cannot find the problem
    Then my bad. I went off of your Title. Repost to C# general and give it a more descriptive title as to how the problem relates to C#. Thanks (They don't give moderators permissions in this forum; hence why you will have to repost).

    William Wegerson (www.OmegaCoder.Com)
    Thursday, February 25, 2010 3:23 PM