字符串插入方法列表增加了其大小



这是代码

    Public Class FrmPatientFolder 
Dim tab1RTBtext As List(Of String)
Dim comboboxprevious As Integer
Dim comboboxcurrent As Integer
Private Sub FrmPatientFolder_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'this contains 12 string which are too long to include in code
tab1combolist = New List(Of String)(New String() {"1",..to..,"12"}
ComboBox1.Items.AddRange(tab1combolist.ToArray)
ComboBox1.SelectedIndex = 0
comboboxprevious = -1
comboboxcurrent = 0
'this performs a select query that either returns a list of 12 strings or nothing
tab1RTBtext = selectFromTable(New List(Of String)(New String() {"*"}), "chronicle", "amka", Me.Text)

If tab1RTBtext Is Nothing Then
tab1RTBtext = New List(Of String)
tab1RTBtext.Add(Me.Text)
For Each item In tab1combolist
tab1RTBtext.Add("")
Next
insertNewPatientIntoTable("chronicle", tab1RTBtext)
tab1RTBtext.RemoveAt(0)
Else         
tab1RTBtext.RemoveAt(0)
RichTextBox1.Rtf = tab1RTBtext(0)
End If
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
     If comboboxprevious <> -1 Then
        comboboxprevious = comboboxcurrent
        comboboxcurrent = ComboBox1.SelectedIndex
    Else
        comboboxcurrent = ComboBox1.SelectedIndex
        comboboxprevious = comboboxcurrent
    End If
    If comboboxcurrent <> comboboxprevious And comboboxprevious <> -1 Then
        Console.WriteLine(tab1RTBtext.Count)
        Console.WriteLine(comboboxprevious & tab1RTBtext(comboboxprevious))
        tab1RTBtext.Insert(comboboxprevious, RichTextBox1.Rtf.ToString)
        Console.WriteLine(tab1RTBtext.Count)
        Console.WriteLine(comboboxprevious & tab1RTBtext(comboboxprevious))
        RichTextBox1.Rtf = tab1RTBtext(comboboxcurrent).ToString
    End If
End Sub

End Sub

,如果在运行时选择ComboBox的第二项

,就会发生这种情况
12
0
13
0{rtf1ansiansicpg1253deff0deflang1032{fonttbl{ffnilfcharset161 Trebuchet MS;}}
viewkind4uc1pardf0fs24par
}

所以我告诉列表,如果Combobox的索引更改,则将RichTextbox.rtf存储在上一个Combobox项目的索引中。但是,每当调用插入方法时,都会增加列表大小。为什么这会发生???除此之外,当我在Combobox中更改所选项目时,它不执行它应该的内容,它不会显示正确的值,这意味着列表的大小不是从末端扩展而是从插入点扩展?

也许这里的RTF处理是错误的,我应该检查使用空字符串格式化,然后在存储之前清除内容,但我无法想象这对我面临的问题有任何影响。

我在此处阅读https://www.dotnetperls.com/list-istert,列表类是针对添加方法优化的,如果一个人想使用insert,则应考虑使用LinkedList类,但是如果我是为此,我必须在许多其他地方调整我的代码。

更改此

tab1RTBtext.Insert(comboboxprevious, RichTextBox1.Rtf.ToString)

进入

tab1RTBtext(comboboxprevious) = RichTextBox1.Rtf.ToString

,当您对方法的工作方式做出假设时,就会发生这种情况。希望您笑得开心,或者至少咯咯笑。:)

相关内容

  • 没有找到相关文章

最新更新