- PR -

ListViewについて

1
投稿者投稿内容
freedom56
会議室デビュー日: 2003/12/15
投稿数: 4
投稿日時: 2003-12-15 17:29
はじめまして。freedom56です。

vb.netでの質問なのですが、ListViewで特定の項目だけを強調表示させることはできないのでしょうか。よろしくお願いします。
sou
ベテラン
会議室デビュー日: 2002/09/25
投稿数: 56
投稿日時: 2003-12-16 22:27
こんばんは。

ListViewで特定の項目だけを強調表示するには、ListViewItemのフォントや前景色、背景色をいじれば出来ます。
下に示したサンプルは一つ目の項目を太字に、2つ目の項目を下線付きで表示します。そして、3つ目の項目を赤色で表示します。
(VBは久しく触っていないのでひょっとしたら違っているかもしれません)

コード:
[C#]
for(int i = 0;i < listView1.Items.Count ; i++)
{
    if(i == 0)
    {
       listView1.Items[i].Font = new Font(listView1.Items[i].Font,FontStyle.Bold);
    }

    if(i == 1)
    {
       listView1.Items[i].Font = new Font(listView1.Items[i].Font,FontStyle.Underline);
    }

  if(i == 2)
    {
       listView1.Items[i].ForeColore = Color.Red;
    }

}

[VB]
Dim i As Integer

For i = 0 To listView.Items.Count -1
   If i = 0 Then
      listView1.Items.Item(i).Font = new Font(listView1.Items.Item(i).Font,FontStyle.Bold)
   End If

   If i = 1 Then
      listView1.Items.Item(i).Font = new Font(listView1.Items.Item(i).Font,FontStyle.Underline)
   End If

   If i = 2 Then
      listView1.Items.Item(i).ForeColor = Color.Red
   End If

Next

1

スキルアップ/キャリアアップ(JOB@IT)