-2

1 つのリスト ビューとテキスト ボックスのフォームがあります。
* リスト ビューには合計 100 行のデータがあります
* リスト ビューには 5 つの列があります
* 列 3 には可能な単語が 2 つしかありませんyesまたはno

yes3列目の単語の出現回数を数えたい

合計行は、次のコードで数えることができます:

''''''''''COUNT TOTAL ADMISSION''''''''''''''

Dim rowcount As Integer = 0

For Each item As ListViewItem In LVfeestatementBA_I.Items
  rowcount = CInt(item.SubItems(0).Text) 'Considering every column always have some value
Next

txttotaladBA_I.Text = rowcount.ToString()

どんな助けでも素晴らしいでしょう

編集1

これは学校の課題です。私が言ったように、私の目的は列3の単語の出現回数を見つけることです。コードに接続され、リストビューのデータを提供するMSアクセスのデータベースがあります。リスト ビューには 5 つの列があり、合計で 100 行あります。col-3 のデータにはgenocc、 、の 3 つの単語のみが含まれていccます。ここで、コード付きの単語の col-3 をカウントし、(68) のような数を表示しますtextbox1

編集2

thedarkspoon が提供する機能を適用しましたが、結果が表示されません。結果をに表示したいだけですtextbox1。単語の総数が78その時点であるform_load場合は、 に表示78されtextbox1ます。最後に変数を追加して問題を解決し、textbox1.text = numofyes変数integerstring現在の作業に変更しました

4

2 に答える 2

1

私はあなたのシナリオをよく理解していませんでした (もっと明確にする必要があります)。

いずれにせよ、それぞれ 3 つのサブアイテムを持つアイテムを表示する ListView が与えられ、3 番目のサブアイテムの値が「yes」または「no」であることがわかっている場合、(linq を使用して) 次のようなクエリを作成できます。

     var collectionOfListViewItems = listView1.Items.Cast<ListViewItem>();
     var numberOfrowsWithTheThirdSubItemTextEqualToYes = (from c in collectionOfListViewItems where c.SubItems[3].Text == "yes" select c).Count();        

linq がなければ、foreach を実行できます。

     var numberOfrowsWithTheThirdSubItemTextEqualToYes = 0;
     foreach (ListViewItem  item in listView1.Items)
     {
        if (item.SubItems[3].Text == "yes")
           numberOfrowsWithTheThirdSubItemTextEqualToYes++;
     }
于 2012-06-01T19:24:01.627 に答える
1

わかりました、これを関数にしましたが、これをサブルーチンに簡単に適応させることができます:

Function countyes()
    'Set up a variable to count the number of yes:
    Dim numofyes As Integer = 0
    'Count the number of yes (Replace listview1 with the name of your listview):
    For Each item As ListViewItem In ListView1.Items
        'If the Yes/No is in column 3, you are looking in subitem 2:
        If item.SubItems(2).Text = "Yes" Then
            'Increment the variable by one if the value is yes:
            numofyes = numofyes + 1
        End If
    Next
    'Return our total number of Yes that we found:
    Return numofyes
End Function

お役に立てれば!

于 2012-06-02T17:19:13.717 に答える