💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
List Control控件是使用频率比较高的一个控件,用它可以很好的做为数据报表的工具,而且比较方便操作和响应,经常可以和数据库相互配合,它就像数据库中的一张表一样,来显示数据库中的数据。 下面结合实例从List Control的样式及列名设置、数据设置和双击响应操作等几个方面,详细介绍List Control控件的使用方法。(完整的实例可在我的CSDN资源中下载:[http://download.csdn.net/detail/margin1988/4570315](http://download.csdn.net/detail/margin1988/4570315)) 首先,在界面中新加一个List Control控件,在其“属性”中的“View”选项中选择“Report”。其次,给该控件添加控件变量:**CListCtrl m_listctrl; **。最后,给该控件添加双击事件响应“NM_DBLCLK”。 (1)样式及列名设置 ~~~ //list control控件显示样式设置 DWORD dwStyle = m_listctrl.GetExtendedStyle(); dwStyle |= LVS_EX_FULLROWSELECT; //使整行高亮 dwStyle |= LVS_EX_GRIDLINES;//网格线 m_listctrl.SetExtendedStyle(dwStyle); m_listctrl.InsertColumn(0,"ID号",LVCFMT_LEFT,100); m_listctrl.InsertColumn(1,"姓名",LVCFMT_LEFT,100); m_listctrl.InsertColumn(2,"性别",LVCFMT_LEFT,100); m_listctrl.InsertColumn(3,"年龄",LVCFMT_LEFT,100); m_listctrl.InsertColumn(4,"联系地址",LVCFMT_LEFT,100); m_listctrl.InsertColumn(5,"联系电话",LVCFMT_LEFT,100); m_listctrl.InsertColumn(6,"Email",LVCFMT_LEFT,100); ~~~ (2)数据设置 ~~~ //list control控件数据设置 CString str; for (int i=0;i<5;i++) { str.Format("%d",i); m_listctrl.InsertItem(i,str.GetBuffer()); for (int j=1;j<7;j++) { m_listctrl.SetItemText(i,j,"你好"); } } ~~~ (3)双击响应操作 ~~~ POSITION pos = m_listctrl.GetFirstSelectedItemPosition(); int index = m_listctrl.GetNextSelectedItem(pos); CString str; str.Format("您双击了第%d行!",index); if(index>=0) MessageBox(str); ~~~