2016-12-16 5 views
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 
} 

でコンボボックスの2番目の項目を選択した場合に何が起こるかでありますコンボボックスのインデックスが変更された場合は、richtextbox.rtfを以前のコンボボックスアイテムのインデックスに格納します。また、insertメソッドが呼び出されるたびに、リストサイズが増加します。なぜこうなった???それ以外にも、コンボボックスで選択した項目を変更すると、それは想定されていることをしません。正しい値が表示されません。つまり、リストのサイズは最後から拡張されずに挿入ポイントから拡張されます。

ここではrtfの処理が間違っている可能性があります。空の文字列で書式を確認してから内容を消去してから、どうやって問題に直面するのか想像できません。

ここでは、リストクラスがaddメソッド用に最適化されていて、insertを代わりに使用したい場合はlinkedlistクラスの使用を検討する必要がありますが、それを行うにはコードを適合させる必要があります他の多くの場所で。

+0

まあ私はばかです...この場合は使用しないでください...私は前のインデックスで私のリストの中に値を置くべきです...いいえ誰も明らかにしたいと思います。 – kokotas

答えて

0

変更この

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

tab1RTBtext(comboboxprevious) = RichTextBox1.Rtf.ToString 

に、これはあなたが方法がどのように機能するかについての仮定を行うときに何が起こるかです。私はあなたが良い笑いを持っていたり、少なくとも笑いを抱いていて願っています。 :)

関連する問題