2011-05-05 69 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

相关问题