我想我对阵列列表的工作原理感到困惑,或者很可能是我的代码???
对于我的应用程序,我将数值输入数字向上/向下控件,然后单击按钮。该按钮将值添加到ArrayList。然后,我单击一个不同的按钮,将ArrayList中的所有值显示为富文本框控件。但值是重复的。在富文本框中看起来像这样的东西
100
200个
200个
300个
300个
300个
425个
425个
425个
425
我在哪里指导错误?
lftMtrAccelRates.Add(LftMtr_Accel_Incr.Value)
lftMtrAccelRates.TrimToSize()
Private Sub btnPrintArray_Click(sender As Object, e As EventArgs) Handles btnPrintArray.Click
Dim message = String.Join(Environment.NewLine, lftMtrAccelRates.ToArray())
rchTxtBox.Text = message
End Sub
答案 0 :(得分:0)
Dim rowNumber As Integer = 1
Dim rowNumber2 As Integer = 1
For Each row As DataGridViewRow In LftMtr_Data_Grid.Rows
If row.IsNewRow Then Continue For
row.HeaderCell.Value = "Step " & rowNumber
LftMtr_Data_Grid.CurrentCell = LftMtr_Data_Grid.Rows(LftMtr_Data_Grid.RowCount - 1).Cells(0)
LftMtr_Data_Grid.CurrentRow.Cells(0).Value = LftMtr_Accel_Incr.Value
LftMtr_Data_Grid.CurrentRow.Cells(1).Value = LftMtr_Decel_Incr.Value
LftMtr_Data_Grid.CurrentRow.Cells(2).Value = LftMtr_Speed_Incr.Value
LftMtr_Data_Grid.CurrentRow.Cells(3).Value = test_Time_Incr1.Value
Me.LftMtr_Data_Grid.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
Me.LftMtr_Data_Grid.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
Me.LftMtr_Data_Grid.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
Me.LftMtr_Data_Grid.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
rowNumber = rowNumber + 1
'lftMtrAccelRates.Add(LftMtr_Data_Grid.CurrentRow.Cells(0).Value)
'lftMtrAccelRates.Add(LftMtr_Accel_Incr.Value)
'lftMtrAccelRates.TrimToSize()
'txtboxArrayVal1.Text = lftMtrAccelRates.Capacity
Next