먼저 아래와 같이 DataTable을 설정합니다. Desc, Price 및 표시 할 전체 문자열이있는 3 열이 추가되었습니다.VB.NET DataTable에서 선택한 행을 제거하고 CheckedListBox로 업데이트하는 방법?
checkBoxDT = New DataTable
checkBoxDT.Columns.Add(New DataColumn With
{.ColumnName = "Desc", .DataType = GetType(String)})
checkBoxDT.Columns.Add(New DataColumn With
{.ColumnName = "Price", .DataType = GetType(Decimal)})
checkBoxDT.Columns.Add(New DataColumn With
{.ColumnName = "DisplayText", .DataType = GetType(String),
.Expression = "Desc + ' - RM ' + Price"})
그런 다음 새 Dataview를 만들고 CheckedListBox1을 DataTable에 바인딩합니다.
checkListView = New DataView(checkBoxDT)
checkListView.Sort = "Desc ASC, Price ASC"
CheckedListBox1.DataSource = checkListView
CheckedListBox1.DisplayMember = "DisplayText"
여기에 내가
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim quan As Integer = 0
Dim currentPrice As Decimal = 0.0
If ComboBox2.SelectedIndex > 0 Then
quan = Convert.ToInt32(ComboBox2.Text.Trim())
currentPrice = Convert.ToDecimal(TextBox3.Text.Trim())
For i As Integer = 1 To quan
checkBoxDT.Rows.Add({ComboBox1.Text, Convert.ToDecimal(TextBox3.Text)})
totalItems = totalItems + 1
totalPrice = totalPrice + currentPrice
Next
Else
currentPrice = Convert.ToDecimal(TextBox3.Text.Trim())
checkBoxDT.Rows.Add({ComboBox1.Text, Convert.ToDecimal(TextBox3.Text)})
totalItems = totalItems + 1
totalPrice = totalPrice + currentPrice
End If
TextBox5.Text = totalItems.ToString()
TextBox4.Text = totalPrice.ToString()
End Sub
아래의 코드로 CheckedListBox1에 새 항목을 추가하지만 난 CheckedListBox1 항목을 삭제에 문제가 있습니다. 여기 내가 시도한 것이있다.
삭제 버튼입니다. 선택한 모든 항목에 대해 CheckedListBox1의 항목을 삭제하려고합니다. 그런 다음 TextBox4에 적절한 가격을 표시하십시오. 삭제할 항목을 하나만 선택하면 정상적으로 작동합니다. 그러나 선택한 여러 항목이 제대로 작동하지 않습니다. 선택되지 않은 다른 항목도 삭제합니다.
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim currentPrice As Decimal = 0.0
While CheckedListBox1.CheckedItems.Count > 0
currentPrice = Convert.ToDecimal(CType(CheckedListBox1.SelectedItems(0), DataRowView).Item("Price").ToString())
totalPrice = totalPrice - currentPrice
totalItems = totalItems - 1
checkListView.Delete(CheckedListBox1.SelectedIndex())
End While
TextBox4.Text = totalPrice.ToString()
TextBox5.Text = totalItems.ToString()
End Sub
하는이 시도 : HTTP : //vbcity.com/blogs/xtab/archive/2010/09/22/how-to-delete-selected- items-from-a-checklistbox.aspx delete 사용 remove – coder32
@ coder32 이미 가이드를 보았습니다. 아직도 내가 원하는 것을 할 수 없으므로 여기에 질문을 올렸습니다. – Student
[확인 된 행을 다른 DataGridView에 표시] (http://stackoverflow.com/q/37113690/1070452) – Plutonix