My situation is that on my windows form , I have several Comboboxes containing several different categories of food products for sale in a transaction.

I have a textbox located next to each ComboBox so whenever I choose an item from the Combobox the cost of that item that I have set to it in a datatable , appears in the TextBox beside it. I also have a separate "total price" textbox that adds up the total from all the textboxes for the transaction

My problem is that I have all the food products set into each ComboBox they should be in , but I do not know how to go about getting the cost to enter into the textbox as I choose a food item.

This is my code for the Form at the moment.

If anyone could even point me in the right direction I'd be really grateful..

I was thinking along the lines of
txtChips.Text = cbChips.SelectedItem or something but I need to access the Product_Cost part of the dataTable that is associated with each Product and I'm at a loss at how I do it..

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 System.Data.SqlClient;

namespace test
{
  public partial class FormTransactions : Form
  {

    DataSet ds = new DataSet();
    SqlConnection cs;
    SqlDataAdapter da;
   

    public FormTransactions()
    {
      InitializeComponent();
    }

    private void FormTransactions_Load(object sender, EventArgs e)
    {
      cs = new SqlConnection();
      da = new SqlDataAdapter();     

      cs.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Employee.mdf;Integrated Security=True;User Instance=True";

      // Chips

      string sql = "SELECT * From TableProduct WHERE Product_Category = 1";

      da = new SqlDataAdapter(sql, cs);
     
      ds.Clear();
      da.Fill(ds,"Product");

      cbChips.DataSource = ds.Tables["Product"];
      cbChips.DisplayMember = "Product_Name";

      // Drinks
      

      sql = "SELECT * From TableProduct WHERE Product_Category = 2";

      da = new SqlDataAdapter(sql, cs);


      da.Fill(ds, "Product1");

      cbDrink.DataSource = ds.Tables["Product1"];
      cbDrink.DisplayMember = "Product_Name";

      // Burger
      

      sql = "SELECT * From TableProduct WHERE Product_Category = 3";

      da = new SqlDataAdapter(sql, cs);


      da.Fill(ds, "Product2");

      cbBurger.DataSource = ds.Tables["Product2"];
      cbBurger.DisplayMember = "Product_Name";      

      // Fish

      sql = "SELECT * From TableProduct WHERE Product_Category = 4";

      da = new SqlDataAdapter(sql, cs);

      da.Fill(ds, "Product4");

      cbFish.DataSource = ds.Tables["Product4"];
      cbFish.DisplayMember = "Product_Name";


      // Others

      sql = "SELECT * From TableProduct WHERE Product_Category = 5";

      da = new SqlDataAdapter(sql, cs);

      da.Fill(ds, "Product5");

      cbOther.DataSource = ds.Tables["Product5"];
      cbOther.DisplayMember = "Product_Name";

      // Tubs

      sql = "SELECT * From TableProduct WHERE Product_Category = 6";

      da = new SqlDataAdapter(sql, cs);

      da.Fill(ds, "Product6");

      cbTub.DataSource = ds.Tables["Product6"];
      cbTub.DisplayMember = "Product_Name"; ;//.DataSource = ds.Tables["Product6"];
      


      // Chicken

      sql = "SELECT * From TableProduct WHERE Product_Category = 7";

      da = new SqlDataAdapter(sql, cs);

      da.Fill(ds, "Product7");

      cbChicken.DataSource = ds.Tables["Product7"];
      cbChicken.DisplayMember = "Product_Name";      
      
      
    }

    private void txtChipPrice_TextChanged(object sender, EventArgs e)
    {
      
      
    }

    private void txtDrinkPrice_TextChanged(object sender, EventArgs e)
    {

    }

    private void txtBurgerPrice_TextChanged(object sender, EventArgs e)
    {

    }

    private void txtChickenPrice_TextChanged(object sender, EventArgs e)
    {

    }

    private void txtFishPrice_TextChanged(object sender, EventArgs e)
    {

    }

    private void txtTubPrice_TextChanged(object sender, EventArgs e)
    {

    }

    private void txtPriceOther_TextChanged(object sender, EventArgs e)
    {

    }

    private void txtTotalPrice_TextChanged(object sender, EventArgs e)
    {

    }

    private void btnCalculate_Click(object sender, EventArgs e)
    {

    }

  }
}
kvprajapati commented: Welcome & Thanks. First post with code [tags] +9

If cost of product is stored in TableProduct then you can retrieve using,

string sql = "SELECT * From TableProduct WHERE Product_Category = 1";

      da = new SqlDataAdapter(sql, cs);
     
      ds.Clear();
      da.Fill(ds,"Product");

      cbChips.DataSource = ds.Tables["Product"];
      cbChips.DisplayMember = "Product_Name";
      cbChips.ValueMember = "cost";
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.