2011-05-05 70 views
0

我想將一個選定的值從數據綁定組合框傳遞給一個帶有文檔ID的表。我試圖將選定的值傳遞給另一個表。當我執行我的代碼時,我在字段中取得了System.data.datarow而不是值。此外,該值不會留在框中。有問題的組合框是docRelComboBox ...其他組合框功能正常,但它不是數據綁定。如何讓組合框將正確的值傳遞給表?

這裏是我用來傳遞值代碼:

private void button1_Click(object sender, EventArgs e) 
     { 
      string intType = interestTypeComboBox.SelectedItem.ToString(); 
      string document = docRelComboBox.SelectedItem.ToString(); 
      string first = firstTextBox.Text; 
      string mid = middleTextBox.Text; 
      string last = lastTextBox.Text; 
      string com = comNameTextBox.Text; 
      string alias = aliasTextBox.Text; 
      string intNotes = interestNotesTextBox.Text; 

      DataClasses1DataContext db = new DataClasses1DataContext(); 

      var matchedIntNumber = (from c in db.GetTable<Interest>() 
            where c.InterestsKey == Convert.ToInt32(interestsKeyTextBox.Text) 
            select c).SingleOrDefault(); 

      matchedIntNumber.InterestType = intType; 
      matchedIntNumber.DocRel = document; 
      matchedIntNumber.First = first; 
      matchedIntNumber.Middle = mid; 
      matchedIntNumber.Last = last; 
      matchedIntNumber.ComName = com; 
      matchedIntNumber.Alias = alias; 
      matchedIntNumber.InterestNotes = intNotes; 

      db.SubmitChanges(); 

     } 

我的組合框中數據源是documentsBindingSource這是正確的,顯示部件是的DocID這是正確的,valuemember是的DocID(不知道這是正確的)並不確定如何處理選定的值。任何幫助都會很棒。

回答

1

使用docRelComboBox.SelectedValue而不是docRelComboBox.SelectedItem

+0

@mssergeant哇工作非常感謝你!現在我可以發佈這個東西=)。 – korrowan 2011-05-05 13:48:11

相關問題