0
下面是代码列表增加其大小
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
,这是,如果在运行时
12
0
13
0{\rtf1\ansi\ansicpg1253\deff0\deflang1032{\fonttbl{\f\fnil\fcharset161 Trebuchet MS;}}
\viewkind4\uc1\pard\f0\fs24\par
}
选择组合框的第二项所以我告诉列表会发生什么,如果组合框的索引改变了,将richtextbox.rtf存储在前一个组合框项目的索引处。但每次调用插入方法时,都会增加列表大小。这是为什么发生?除此之外,当我更改组合框中的选定项目时,它没有按照它应该做的那样去做,它不显示正确的值,这意味着列表的大小不会从最后扩展而是从插入点扩展?
也许在这里rtf的处理是错误的,我应该检查格式与空字符串,然后清除内容之前存储,但我无法想象这可能会对我面临的问题有任何影响。
我在这里读到https://www.dotnetperls.com/list-insert列表类是为add方法优化的,如果想要使用insert代替,应该考虑使用linkedlist类,但是如果我要这样做,那么我将不得不调整我的代码在许多其他地方。
嗯,我很愚蠢......在这种情况下不应该使用插入......我应该直接将值放在我的列表中以前的索引......难怪没有人想陈述明显。 – kokotas