2012-06-06 67 views
1

我有下面的代碼使用一個數據集來填充兩個組合框:vbnet多個組合框填充一個數據集

Private Sub sub_cbo_type_load() 
    Dim ds As New DataSet 
    ds = cls.cbo_type() 
    If ds IsNot Nothing _ 
    AndAlso ds.Tables.Count > 0 _ 
    AndAlso ds.Tables(0).Rows.Count > 0 Then 
     Me.r_cbo_type.DataSource = ds.Tables(0) 
     Me.r_cbo_type.DisplayMember = "desc" 
     Me.r_cbo_type.ValueMember = "code" 
     Me.r_cbo_type.SelectedIndex = -1 
     Me.m_cbo_type.DataSource = ds.Tables(0) 
     Me.m_cbo_type.DisplayMember = "desc" 
     Me.m_cbo_type.ValueMember = "code" 
     Me.m_cbo_type.SelectedIndex = -1 
    End If 
End Sub 

的問題是:每當該指數是在一個組合框中改變,它會自動在另外一個改變太。

沒有人知道我該如何解決這個問題?

感謝您的時間。

回答

1

嘗試複製表:

Private Function CopyTable(ByVal sourceTable As DataTable) As DataTable 
    Dim newTable As DataTable = sourceTable.Clone 
    For Each row As DataRow In sourceTable.Rows 
    newTable.ImportRow(row) 
    Next 
    Return newTable 
End Function 

那麼你的數據源將引用不同的來源:

Me.r_cbo_type.DataSource = CopyTable(ds.Tables(0)) 

Me.m_cbo_type.DataSource = CopyTable(ds.Tables(0)) 
+0

非常感謝larstech!有效。 – Eccaos

0

做這樣

Private Sub btn_update1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_update1.Click 
     If MsgBox("Are you sure to update?" & "", MsgBoxStyle.YesNo, "Confirmation") = MsgBoxResult.Yes = True Then 
      Dim transmode As String = vbNullString 
      Dim byair As String = vbNullString 
      Dim bysea As String = vbNullString 
      If rb_air.Checked = True Then 
       transmode = "A" 
       byair = txt_mserial.Text '.Substring(txt_mserial.TextLength - 4, 4) 
       bysea = vbNullString 
      ElseIf rb_sea.Checked = True Then 
       transmode = "B" 
       byair = vbNullString 
       bysea = txt_mserial.Text '.Substring(txt_mserial.TextLength - 4, 4) 
      End If 
      Try 
       If con.State = ConnectionState.Closed Then con.Open() 
       global_command = New SqlCommand("update ytmi_finished_products set rev_ctrl_no = '" & txt_mrev.Text & "', by_air = '" & byair & "', by_sea = '" & bysea & "', transport_mode = '" & transmode & "' where REPLACE(prod_no, '-', '') +'-'+ ISNULL(CONVERT(varchar(50), prod_sx), '') + prod_lvl = '" & txt_mpart.Text & "' and cast(serial_no as numeric) = '" & txt_mserial.Text & "' and req_box_qty = '" & txt_mqty.Text & "' and remarks is null", con) 
       global_command.ExecuteNonQuery() 
       global_command.Dispose() 

       MsgBox("Successfully Updated!", MsgBoxStyle.Information, "Message") 
       mclear() 
      Catch ex As Exception 
       MsgBox("Trace No 20: System Error or Data Error!" + Chr(13) + ex.Message + Chr(13) + "Please Contact Your System Administrator!", vbInformation, "Message") 
      End Try 
     End If 
    End Sub 
相關問題