因此,我一直在瀏覽有關如何將數據從列表框移動到列表框的說明。 我有一個列表框綁定到我的SQL服務器和另一個未綁定的源。我的目標是將數據從第一個(LBsearch)
移到第二個(LBselect)
並返回。我看到有人說使用 LBselect.Items.Add(LBsearch.SelectedItem)
但是它不返回數據,而是顯示System.Data.DataRowView
。我已經嘗試了許多不同的後綴,並且都從LBsearch.text
中分辨出來。然後從第一個刪除數據我一直在刪除數據綁定來源(PersonBindingSource)
與 PersonBindingSource.Remove(LBsearch.SelectedItem)
但我的問題是再次添加數據。將數據從數據綁定列表框移動到未綁定列表框並返回VB.NET
PersonBindingSource.Add(LBselect.SelectedItem)
給出了一個錯誤:
System.InvalidOperationException: Objects added to a BindingSource's list must all be of the same type.
at System.Windows.Forms.BindingSource.Add(Object value)
at Project_Program.Participants.btnremoveselect_Click(Object sender, EventArgs e) in E:\Documents\Visual Studio\Project Program\Project Program\Participants.vb:line 39
PersonBindingSource.Add(PersonBindingSource.Item(LBsearch.SelectedIndex))
給出了一個錯誤:
System.ArgumentException: Cannot add external objects to this list.
at System.Data.DataView.System.Collections.IList.Add(Object value)
at System.Windows.Forms.BindingSource.Add(Object value)
at Project_Program.Participants.btnremoveselect_Click(Object sender, EventArgs e) in E:\Documents\Visual Studio\Project Program\Project Program\Participants.vb:line 38
任何幫助,將不勝感激。由於
Private Sub btnaddselect_Click(sender As Object, e As EventArgs) Handles btnaddselect.Click
If LBsearch.Items.Count > 0 Then
MsgBox(LBsearch.Text)
' PersonBindingSource.Remove(PersonBindingSource.Item(LBsearch.SelectedIndex))
LBselect.Items.Add(LBsearch.Text)
PersonBindingSource.Remove(LBsearch.SelectedItem)
' filter()
End If
End Sub
Private Sub btnremoveselect_Click(sender As Object, e As EventArgs) Handles btnremoveselect.Click
If LBselect.Items.Count > 0 Then
Try
'PersonBindingSource.Add(PersonBindingSource.Item(LBsearch.SelectedIndex))
PersonBindingSource.Add(LBselect.SelectedItem)
MsgBox(LBselect.SelectedItem.ToString())
LBselect.Items.Remove(LBselect.SelectedItem)
Catch ex As Exception
TextBox1.Text = (ex.ToString)
End Try
'filter()
End If
End Sub
被綁定的那個數據庫行通過DataView「映射」到它。如果您設置了ValueMember,則在ValueChanged事件中,SelectedValue會爲您提供該行。我不知道你想要放在另一個LB上;如果要添加行,請設置DisplayMember和ValueNenber屬性,或者顯示文本,從SelectedValue獲取 - 將其轉換爲DataRow並獲取所需的任何字段 – Plutonix
可能的重複[如何檢測移動設備javascript?](http://stackoverflow.com/questions/6666907/how-to-detect-a-mobile-device-with-javascript) –