
第一步:在窗体中拖入ListView控件和imageList控件;
第二步:设置imageList控件的Images属性,添加你想要的;
第三步:设置ListView控件的SmallImageList、LargeImageList、StateImageList属性为imageList;
第四步:编辑ListView控件项的ImageIndex行为你就会发现成功显示出来了!
附:在ListView控件中添加选项的代码
private void button1_Click(object sender, EventArgs e)
{
if (textBox1Text == "")
{
MessageBoxShow("添加的内容不能为空");
textBox1Focus(); //获取焦点
}
else
{
if (listView1ItemsCount > 0) //判断列表框中是否有项
{
//循环比较是否有重复项,有则放弃添加
for (int i = 0; i < listView1ItemsCount; i++)
{
if (stringCompare(listView1Items[i]TextToString(), textBox1Text) == 0)
{
MessageBoxShow("项目重复,不能添加!");
textBox1Text = ""; //清空文本框
textBox1Focus();
return;
}
}
listView1ItemsAdd(textBox1TextToString());
textBox1Text = "";
}
else
{
listView1ItemsAdd(textBox1TextToString()); //将文本框中的数据添加到列表框
textBox1Text = "";
}
}
}
现在设计里双击listview,就会产生 listView1_SelectedIndexChanged(object sender, EventArgs e)的函数,函数应该如下写:(根据你的listView的名称更改下面listView1)
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listView1SelectedIndices != null && listView1SelectedIndicesCount > 0)
{
ListViewSelectedIndexCollection c = listView1SelectedIndices;
textBox1Text = listView1Items[c[0]]SubItems[2]Text;
}
}
选中项的文本值:thislistView1SelectedItems[0]Text;
选中项的子项的文本值
thislistView1SelectedItems[0]SubItems[0]Text;(SubItems[0]表示选中项的第一个子项,第二个子项就是SubItem[1],第三个就是SubItems[2]以此类推)
string s=null;
for (int i = 0; i < listView1ItemsCount; i++)
{
ListViewItem item = listView1Items[i];
for (int j = 0; j < itemSubItemsCount; j++)
{
s =s+itemSubItems[j]Text;
textBox1Text = s;
}
}
我只是用TextBox来给你演示怎么拿出所有的东西,你具体是用什么东西装改掉TextBox1就可以了·
ListView是MVC架构的view,是对listctrl的包装。要得到标题,须这样。
假定窗口句柄 theListView;
CListCtrl& theCtrl = theListView->GetListCtrl();
TCHAR buffer[256];
LVCOLUMN col;
colmask= LVCF_TEXT;
colpszText= buffer;
colcchTextMax= 256;
theCtrlGetColumn(1,&col);// 获取第二列的标题。结果保存在buffer;
// 更改标题也是一样,先在buffer中写入标题内容,然后
theCtrlSetColumn(1,&col);
以上就是关于在C#中怎么用代码向listView中添加图片各文字全部的内容,包括:在C#中怎么用代码向listView中添加图片各文字、c# listview控件中如何在选中某一行时将此行的第3列数据提取到文本框中显示、怎样获取listview里项被选中时的的值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)