Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

Deleting listbox items with database values c#

imba23

Professional
Advanced Member
Messages
165
Reaction score
0
Points
26
mga sir pahelp naman sa problema ko, ganto po yung flow, ang una po magaadd ako ng items sa listbox (for example "Package1" with price of 3999) & nagdagdag po ako ng panibagong items (ex. "Package2" price: 2999) kapag tinanggal ko po yung "Package1" sa listbox gamit po yung doubleclick event ang mangyayari mababwasan po yung Total, magiging 2999 na lang po ulet

eto po yung image ng form
View attachment 307324

eto po yung code ko:
Code:
private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            string constring = "server=localhost;port=3306;username=root;password=root";
            string Query = "Select * from dbinfo.tbladvance;";
            MySqlConnection con = new MySqlConnection(constring);
            MySqlCommand cmdDB = new MySqlCommand(Query, con);
            MySqlDataReader myReader;

            con.Open();
            myReader = cmdDB.ExecuteReader();

            while (myReader.Read())
            {
                /* for (int n = listBox1.Items.Count - 1; n >= 0; --n)
                {
                    string sName = myReader.GetString("Names");
                    string removelistitem = sName;
                    if (listBox1.Items[n].ToString().Contains(removelistitem))
                    {
                        listBox1.Items.RemoveAt(n);
                    }
                } */
                {
                    for (int i = 0; i < listBox1.SelectedItems.Count; i++)
                        listBox1.Items.Remove(listBox1.SelectedItems[i]);
                }
            }
            con.Close();
        }
        void fillCombo()
        {

            string constring = "server=localhost;port=3306;username=root;password=root";
            string Query = "Select * from dbinfo.tbladvance;";
            MySqlConnection con = new MySqlConnection(constring);
            MySqlCommand cmdDB = new MySqlCommand(Query, con);
            MySqlDataReader myReader;
            try
            {
                con.Open();
                myReader = cmdDB.ExecuteReader();

                while (myReader.Read())
                {
                    string sName = myReader.GetString("Names");
                    comboBox1.Items.Add(sName);



                }
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void Trans_Load(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string constring = "server=localhost;port=3306;username=root;password=root";
            string Query = "Select * from dbinfo.tbladvance where Names='" + comboBox1.Text + "'  ;";
            MySqlConnection con = new MySqlConnection(constring);
            MySqlCommand cmdDB = new MySqlCommand(Query, con);
            MySqlDataReader myReader;
            try
            {
                con.Open();
                myReader = cmdDB.ExecuteReader();

                while (myReader.Read())
                {
                    string sName = myReader.GetString("Names");
                    double sPrice = myReader.GetDouble("Price");
                    string sDesc = myReader.GetString("Description");
                    txtName.Text = sName;
                    txtPrice.Text = sPrice.ToString();
                    txtDesc.Text = sDesc;
                }
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        int total;
        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Add(txtName.Text);

            int num1 = int.Parse(txtPrice.Text);
            int num2 = int.Parse(txtTotal.Text);

            total = num1 + num2;

            txtTotal.Text = total.ToString();
        }

Bali ang problem ko na lang po mga sir is yung pag remove ng items then deduction dun sa total :( sana matulungan nyo po ako, Thank you!

- - - Updated - - -

Up lang po need ko lang talaga :(
 

Attachments

  • sample.PNG
    sample.PNG
    10.4 KB · Views: 8
Back
Top Bottom