Hey there, =)

My head is almost through with my database im working on. I just need one more thing i Cant seem to do.

Now this is my code for connecting to my datagridview

String connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\Resources\\db1.mdb";
           string query = "SELECT * FROM Expenditure";

            //create an OleDbDataAdapter to execute the query
            dAdapter = new OleDbDataAdapter(query, connString);

            //create a command builder
            OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);
            //fill the DataTable
            dAdapter.Fill(dTable);

            //the DataGridView
            DataGridView dgView = new DataGridView();

            //BindingSource to sync DataTable and DataGridView
            BindingSource bSource = new BindingSource();

            //set the BindingSource DataSource
            bSource.DataSource = dTable;

            //set the DataGridView DataSource
            tblAllEntries.DataSource = bSource;

Now i have a column called "The Expense" and "Amount". I have already created a variable called Total to calculate the sum of all the integers in the total column. NOW i want to create a row Right at the bottom of the datagridview with the total amount. In other words i want it to look like this

"The Expense"..........."Amount"
Car........................600
House......................900
food.......................200
movies.....................100
Total......................1800


How would i insert that row programmatically. I already have the code worked out to get the total row to create itself at the bottom of everything no matter how much expenses are added or deleted.

Thank you =)
Ruan

dgView.Rows.Add(); //what else?

dgView.Rows.Add(); //what else?

:-O What? Its Databound, You cant just throw a new line in it as easily as that?! youll have to do something like create a new datasource and merge it with the current datasource. Or whatever, but that command wont work At All.

Dont worry I figured out how to do it.

int x = tblAllEntries.Rows.Count; 
            tblAllEntries.Rows[x-1].Cells[0].Value = "TOTAL".ToString();
            tblAllEntries.Rows[x - 1].Cells[1].Value = Budget.ToString();

Chow =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.