C# listview添加combobox到單元格的實(shí)現(xiàn)代碼
更新時(shí)間:2014年06月18日 14:50:07 投稿:mdxy-dxy
從別處轉(zhuǎn)來(lái)的,自己進(jìn)行了一些小的修改,還不錯(cuò),你自己先拖一個(gè)ListView1和一個(gè)ComboBox1,需要的朋友可以參考下
實(shí)現(xiàn)代碼:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { ListViewItem lvi; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { comboBox1.Visible = false; listView1.Columns.Add("第一列"); listView1.Columns.Add("第二列"); listView1.Columns.Add("第三列"); this.comboBox1.Items.Add("科比"); this.comboBox1.Items.Add("姚明"); this.comboBox1.Items.Add("杜蘭特"); this.comboBox1.Items.Add("鄧肯"); ListViewItem item; item = new ListViewItem(1.ToString()); item.SubItems.Add("姚明"); item.SubItems.Add("科比"); listView1.Items.Add(item); item = new ListViewItem(2.ToString()); item.SubItems.Add("鄧肯"); item.SubItems.Add("杜蘭特"); listView1.Items.Add(item); } private void listView1_MouseUp(object sender, MouseEventArgs e) { lvi = this.listView1.GetItemAt(e.X, e.Y); if (lvi != null) { //獲取選中行的Bounds Rectangle Rect = lvi.Bounds; int LX = listView1.Columns[0].Width; int RX = listView1.Columns[0].Width + listView1.Columns[1].Width; // if (e.X > RX || e.X < LX) //{ this.comboBox1.Visible = false; Rect.X = listView1.Left + listView1.Columns[0].Width + 2; Rect.Y = this.listView1.Top + 2+Rect.Y; Rect.Width = listView1.Columns[1].Width + 2; this.comboBox1.Bounds = Rect; this.comboBox1.Text = lvi.SubItems[1].Text; this.comboBox1.Visible = true; this.comboBox1.BringToFront(); this.comboBox1.Focus(); //} // int intColIndex = lvi.SubItems.IndexOf(lvi.GetSubItemAt(e.X, e.Y)); } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { lvi.SubItems[1].Text = comboBox1.Text; // comboBox1.Visible = false; } private void comboBox1_MouseLeave(object sender, EventArgs e) { lvi.SubItems[1].Text = comboBox1.Text; // comboBox1.Visible = false; } } }
您可能感興趣的文章:
- C# ComboBox控件“設(shè)置 DataSource 屬性后無(wú)法修改項(xiàng)集合”的完美解決方法
- C#實(shí)現(xiàn)帶搜索功能的ComboBox
- C# 重寫(xiě)ComboBox實(shí)現(xiàn)下拉任意組件的方法
- C# ComboBox的聯(lián)動(dòng)操作(三層架構(gòu))
- C#實(shí)現(xiàn)ComboBox控件顯示出多個(gè)數(shù)據(jù)源屬性的方法
- C#實(shí)現(xiàn)綁定Combobox的方法
- C#用ComboBox控件實(shí)現(xiàn)省與市的聯(lián)動(dòng)效果的方法
- C#(WinForm) ComboBox和ListBox添加項(xiàng)及設(shè)置默認(rèn)選擇項(xiàng)
- c#構(gòu)造ColorComboBox(顏色下拉框)
- C#實(shí)現(xiàn)ComboBox自動(dòng)匹配字符
- C#中comboBox實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)
相關(guān)文章
C#跨PC遠(yuǎn)程調(diào)用程序并顯示UI界面
這篇文章主要為大家介紹了使用C#跨PC遠(yuǎn)程調(diào)用程序并顯示UI界面,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-05-05C# 獲取當(dāng)前年份的周期及周期所在日期范圍(推薦)
這篇文章主要介紹了C# 獲取當(dāng)前年份的周期,周期所在日期范圍 ,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-05-05C#使用IronPython庫(kù)調(diào)用Python腳本
這篇文章介紹了C#使用IronPython庫(kù)調(diào)用Python腳本的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06基于WPF實(shí)現(xiàn)一個(gè)簡(jiǎn)單的音頻播放動(dòng)畫(huà)控件
這篇文章主要介紹了如何利用WPF實(shí)現(xiàn)一個(gè)簡(jiǎn)單的音頻播放動(dòng)畫(huà)控件,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)或工作有一定幫助,需要的可以參考一下2022-07-07Js中的substring,substr與C#中的Substring比較
本篇文章主要是對(duì)Js中的substring,substr與C#中的Substring進(jìn)行了比較。需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-01-01