Computing.Net > Forums > Programming > using datagrid as temp storage

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

using datagrid as temp storage

Reply to Message Icon

Name: secrets
Date: March 7, 2005 at 05:13:11 Pacific
OS: Windows
CPU/Ram: 2.4HT
Comment:

i am using Visual Basic and i want to some information on DataGrid as temporary storage and then when user click the commit button on form it will be entered into database.
i am newbie to .net please explain it a bit.



Sponsored Link
Ads by Google

Response Number 1
Name: Chi Happens
Date: March 9, 2005 at 10:01:51 Pacific
Reply:

First advice...stop using VB.net. Start using C#...i mean, why learn the .net language and then program in vb?!?! (he he, I am on an anti-vb kick this month)

anyhow...you want to display the information and then let the user hit commit and then save the data, right? Well first you need to get away from using the data binding or you need to use rollback functions.

Personally, I dislike the data-bound objects because they restrict me...but others love them because they do so much for you...

If you MUST use data-bound objects, bind them to a temp table, then when the user hits commit, copy those records to the real table using ODBC objects.

Tell me more about the back-end (database) as well as the front-end (GUI) and I can be less vague.

Chi

They mostly come at night...mostly


0

Response Number 2
Name: secrets
Date: March 10, 2005 at 09:08:35 Pacific
Reply:

Chi,
thanks for the C# suggestion...after this i will check that too.....
well! Front End is Visual Basic .net
and Back End is Microsoft SQL Server 2000.
i am not getting stuck with that data bound objects...any other option i will look forward for it..
actually i am creating a cash Voucher....in an accounting System.
now user can enter More then one enteries in order to equal the both side according to the rule of accounting..
means if total cash is 200 the other side can be 10,30,160.....or more combination i want the current entered these values to display in some graphical manner like that data grid. and then if user want to confirm it then he will click commit and its done....


0

Response Number 3
Name: Chi Happens
Date: March 12, 2005 at 20:07:46 Pacific
Reply:

ah well then if you are not using databound controls, then you are in good shape to do what you want.

you have two choices as I see it:

1) create a temporary table in sql and load the info into that table. then when the user clicks commit, copy the contents of the temp table to the actual table.

2) use a System.Collections.ArrayList with a structure inside that holds all the information. when the user clicks commit, loop through the collection and save it to the db.

Hope this helps,
Chi

They mostly come at night...mostly


0

Response Number 4
Name: secrets
Date: March 13, 2005 at 10:06:47 Pacific
Reply:

thanks Chi,
now i like second option kindly guide me a bit how can i show that collection array list in data grid.:)


0

Response Number 5
Name: Chi Happens
Date: March 14, 2005 at 11:50:39 Pacific
Reply:

Well, since I am not certain exactly what data you are using i will just show you a general thing: (this is something you could use as a virtual check book for instance)


NOTE: this form has a listview on it with 5 columns (date, name, deduction, deposit, and total) and two textboxes (1 is name, 2 is amount) and one checkbox (deduction flag) and a button to add the item to the list

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication4
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        public struct ITEM_INFO
        {
            public string EntryDate;
            public string Name;
            public float Amount;
            public bool Deduction;
        }
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (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.listView1 = new System.Windows.Forms.ListView();
            this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
            this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
            this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
            this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
            this.columnHeader5 = new System.Windows.Forms.ColumnHeader();
            this.button1 = new System.Windows.Forms.Button();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.checkBox1 = new System.Windows.Forms.CheckBox();
            this.SuspendLayout();
            // 
            // listView1
            // 
            this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
                                                                                        this.columnHeader1,
                                                                                        this.columnHeader2,
                                                                                        this.columnHeader3,
                                                                                        this.columnHeader4,
                                                                                        this.columnHeader5});
            this.listView1.GridLines = true;
            this.listView1.Location = new System.Drawing.Point(16, 24);
            this.listView1.Name = "listView1";
            this.listView1.Size = new System.Drawing.Size(368, 200);
            this.listView1.TabIndex = 0;
            this.listView1.View = System.Windows.Forms.View.Details;
            // 
            // columnHeader1
            // 
            this.columnHeader1.Text = "date";
            // 
            // columnHeader2
            // 
            this.columnHeader2.Text = "item";
            // 
            // columnHeader3
            // 
            this.columnHeader3.Text = "deduction";
            // 
            // columnHeader4
            // 
            this.columnHeader4.Text = "deposit";
            // 
            // columnHeader5
            // 
            this.columnHeader5.Text = "total";
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(304, 240);
            this.button1.Name = "button1";
            this.button1.TabIndex = 1;
            this.button1.Text = "button1";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(24, 240);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(104, 20);
            this.textBox1.TabIndex = 2;
            this.textBox1.Text = "textBox1";
            // 
            // textBox2
            // 
            this.textBox2.Location = new System.Drawing.Point(136, 240);
            this.textBox2.Name = "textBox2";
            this.textBox2.Size = new System.Drawing.Size(104, 20);
            this.textBox2.TabIndex = 3;
            this.textBox2.Text = "textBox2";
            // 
            // checkBox1
            // 
            this.checkBox1.Location = new System.Drawing.Point(256, 240);
            this.checkBox1.Name = "checkBox1";
            this.checkBox1.Size = new System.Drawing.Size(40, 24);
            this.checkBox1.TabIndex = 4;
            this.checkBox1.Text = "checkBox1";
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(424, 341);
            this.Controls.Add(this.checkBox1);
            this.Controls.Add(this.textBox2);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.listView1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }

        private void Form1_Load(object sender, System.EventArgs e)
        {
            
        }

        private System.Windows.Forms.ListView listView1;
        private System.Windows.Forms.ColumnHeader columnHeader1;
        private System.Windows.Forms.ColumnHeader columnHeader2;
        private System.Windows.Forms.ColumnHeader columnHeader3;
        private System.Windows.Forms.ColumnHeader columnHeader4;
        private System.Windows.Forms.ColumnHeader columnHeader5;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.TextBox textBox2;
        private System.Windows.Forms.CheckBox checkBox1;

        private System.Collections.ArrayList Items = new System.Collections.ArrayList();

        public void AddItem(ITEM_INFO ItemInfo)
        {
            Items.Add(ItemInfo);
        }

        public ITEM_INFO GetItem(string Name,string EntryDate)
        {
            ITEM_INFO ItemInfo = new ITEM_INFO();
            for(int i=0;i<Items.Count;i++)
                                        
            {
                if( ((ITEM_INFO)Items[i]).Name == Name && ((ITEM_INFO)Items[i]).EntryDate == EntryDate)
                                                                                                                        
                {
                    ItemInfo = (ITEM_INFO)Items[i];
                    break;
                }
            }
            return ItemInfo;
        }
        private void AddItemToView()
        {
        }
        private string CalculateRunningTotal()
        {
            float runningtotal = 0;
            for(int r=0;r<listView1.Items.Count;r++)
                                            
            {
                if(listView1.Items[r].SubItems[2].Text != "")
                                                                                                                            
                {
                    runningtotal -= float.Parse(listView1.Items[r].SubItems[2].Text);
                }
                else
                    runningtotal += float.Parse(listView1.Items[r].SubItems[3].Text);

            }
            return runningtotal.ToString();
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            ITEM_INFO ItemInfo = new ITEM_INFO();
            ItemInfo.Amount = float.Parse(textBox2.Text);
            ItemInfo.Name = textBox1.Text;
            ItemInfo.Deduction = checkBox1.Checked;

            AddItem(ItemInfo); // place it into the collection for later saving

            listView1.Items.Add(ItemInfo.EntryDate);
            listView1.Items[listView1.Items.Count-1].SubItems.Add(ItemInfo.Name);

            if(ItemInfo.Deduction)
            { // place item into deduction column
                listView1.Items[listView1.Items.Count-1].SubItems.Add(ItemInfo.Amount.ToString());
                listView1.Items[listView1.Items.Count-1].SubItems.Add("");
            }
            else
            { // place item into deposit column
                listView1.Items[listView1.Items.Count-1].SubItems.Add("");
                listView1.Items[listView1.Items.Count-1].SubItems.Add(ItemInfo.Amount.ToString());
            }
            listView1.Items[listView1.Items.Count-1].SubItems.Add(CalculateRunningTotal());
        }
    }
}


Hope this helps,
Chi

They mostly come at night...mostly


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: using datagrid as temp storage

128-bit integers www.computing.net/answers/programming/128bit-integers/6846.html

Deleting data from DataGrid..? www.computing.net/answers/programming/deleting-data-from-datagrid/6793.html

how to use LPT1 as comunication www.computing.net/answers/programming/how-to-use-lpt1-as-comunication/4476.html