Answered Get valve from combobox (using linq to Sql)

  • Wednesday, March 21, 2012 3:44 PM
     
      Has Code

    I have 2 tables in the database carrier and vendor. vendor has a foreign key of Carrier_Id. When the user want add a vendor, the user will select a carrier from a combobox where the valve from carrier table.

    The problem I facing now is that,I don't know how to get the valve from combobox so that I can insert it into the database.

    I use this code to get valve from carrier table to show in the combobox.

       MyinvoiceDataDataContext contect = new MyinvoiceDataDataContext();
                var st = from s in contect.Carriers
                         select new { s.CarrierID, s.CarrierName };
                comVendorCarrier.ItemsSource = st;
                comVendorCarrier.DisplayMemberPath = "CarrierName";
                comVendorCarrier.SelectedValuePath = "CarrierID";



All Replies

  • Wednesday, March 21, 2012 6:40 PM
     
     

     

    What platform are you using, Desk top, WPF, Web?

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

  • Friday, March 23, 2012 4:12 PM
     
     
    Both Desktop and WPF , using linq to sql.
  • Friday, March 23, 2012 5:06 PM
     
     Answered Has Code
    var item = YourCombobox.SelectedItem;
    item.GetProperty("PropertyName").GetValue(item , null);

    Please mark as reply if helped.
    Also visit my blog http://msguy.net/




  • Saturday, March 24, 2012 3:43 AM
     
      Has Code

    Hi, i found one more way ... i can also use this..

    int SelectedCarrierId = int.parse(comVendorCarrier.SelectedValue.ToString());


  • Saturday, March 24, 2012 6:14 PM
     
     Answered
    Not completely sure about this one, but I meet your case scenario lots of time and solution I've displayed above s 100% reliable

    Please mark as reply if helped.
    Also visit my blog http://msguy.net/