如何在listview中插入圖片,相信大家很想知道,下面就為大家分享具體步驟:
第一步:在窗體中拖入ListView控件和imageList控件;
第二步:設(shè)置imageList控件的Images屬性,添加你想要的圖片;
第三步:設(shè)置ListView控件的SmallImageList、LargeImageList、StateImageList屬性為imageList;
第四步:編輯ListView控件項(xiàng)的ImageIndex行為你就會(huì)發(fā)現(xiàn)圖片成功顯示出來(lái)了!
附:在ListView控件中添加選項(xiàng)的代碼
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "") { MessageBox.Show("添加的內(nèi)容不能為空"); textBox1.Focus(); //獲取焦點(diǎn) } else { if (listView1.Items.Count > 0) //判斷列表框中是否有項(xiàng) { //循環(huán)比較是否有重復(fù)項(xiàng),有則放棄添加 for (int i = 0; i < listView1.Items.Count; i++) { if (string.Compare(listView1.Items[i].Text.ToString(), textBox1.Text) == 0) { MessageBox.Show("項(xiàng)目重復(fù),不能添加!"); textBox1.Text = ""; //清空文本框 textBox1.Focus(); return; } } listView1.Items.Add(textBox1.Text.ToString()); textBox1.Text = ""; } else { listView1.Items.Add(textBox1.Text.ToString()); //將文本框中的數(shù)據(jù)添加到列表框 textBox1.Text = ""; } } }以上就是本文的全部?jī)?nèi)容,希望本文所述對(duì)大家學(xué)習(xí)C#程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選