以combobox为例。

  假如一行里面只有一个combobox。

    //在类中声明一个控件数组
private ComboBox[] cmds = null; //initview中调用dao组件获得显示的对象列表
List<Indicator> plist = idao.queryIndicators(); //根据对象列表个数new一组cmds
cmds=new ComboBox[plist.Count]; //在view的SelectedIndexChanged事件中
if (this.listView1.SelectedItems.Count > )
{
//获得选中的行
ListViewItem item = this.listView1.SelectedItems[];
//获得行号
int index=this.listView1.SelectedIndices[];
cmds[index] = new ComboBox();
for (int i = ; i <= ; i++){
cmds[index].Items.Add(i + "");
cmds[index].SelectedItem = "";
cmds[index].Bounds = item.SubItems[].Bounds;
listView1.Controls.Add(cmds[index]);
cmds[index].Show();
}
}

  如果一行有多个combobox呢? 这和一行一个的区别在于,一行两个不仅需要确定选中的是哪行,还要确定哪列。

  虽然只差这一点,但是实现确完全不同。


  private void indicatorView_MouseMove(object sender, MouseEventArgs e)//获取鼠标位置
  {
    mousePos.X = e.X;
    mousePos.Y = e.Y;
  }

private void indicatorView_Click(object sender, EventArgs e)
{
  ListViewItem item = indicatorView.GetItemAt(mousePos.X, mousePos.Y);//根据鼠标当前位置得到item
  Rectangle rect = item.GetBounds(ItemBoundsPortion.Entire);
  int StartX = rect.Left;
  int ColumnIndex = ;
  int pos = GetScrollPos(this.indicatorView.Handle.ToInt32(), );
  foreach (ColumnHeader Column in indicatorView.Columns)//选中的哪一列
  {
    if (mousePos.X + pos >= StartX + Column.Width)
    {
      StartX += Column.Width;
      ColumnIndex += ;
    }
  }
  if (ColumnIndex == this.indicatorView.Columns.Count - )//如果选中最后一列
  {
    int index = this.indicatorView.SelectedIndices[];
    indicatorViewComboBox[index] = new ComboBox();
    for (int i = ; i <= ; i+=)
      indicatorViewComboBox[index].Items.Add(i + "");
    indicatorViewComboBox[index].SelectedItem = "";
    indicatorViewComboBox[index].Bounds = item.SubItems[ColumnIndex].Bounds;
    indicatorView.Controls.Add(indicatorViewComboBox[index]);
    indicatorViewComboBox[index].Show();
  }
  else if (ColumnIndex == this.indicatorView.Columns.Count - ) { //其他列
  
  } }

ListView单击单元格 产生其他控件的更多相关文章

  1. ios-根据单元格里的控件tag值,在方法外获得对应的section与row的值

    在cell的代理方法里:cellForRowAtIndexPath btn.tag = indexPath.section *100 + indexPath.row; [cell.exitPerson ...

  2. C# 在DataGridView中,点击单元格调出 TreeView控件 或 ListBox控件

    1.调出 TreeView控件 或  ListBox控件 private void deductGrid1_CellClick(object sender, DataGridViewCellEvent ...

  3. 【转】【C#】在 Windows 窗体 DataGridView 单元格中承载控件

    using System; using System.Windows.Forms; public class CalendarColumn : DataGridViewColumn { public ...

  4. gridView 单元格绑定不同控件方法

    1.主要代码: private void Form3_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Col ...

  5. easyui datagrid单击单元格选择此列

    示例代码实现单击jquery easyui datagrid的单元格时,取消datagrid默认选中高亮此行的样式,改为选中单击的单元格所在的列,高亮此列上的所有单元格.可以配置全局single变量, ...

  6. asp.net gridview中增加单击单元格事件

    实现功能:单击表格中某个单元格(不是第一列.最后一列.最后一行,不为0)根据行第一个单元格内容及列名来查询详细内容,在消息框中查看显示. 在代码中增加 protected override void ...

  7. Gridview 重建表头/单击单元格弹出对话框/改变单元格背景色

    整理工作~ 完整的代码在GitHub上, 路径: 项目背景:追踪某个issue,并且记录每天的状态. 要求:1.点击日期就能更改,并且用颜色标志不同的状态 2.增加按钮可关闭issue 3.布局要求日 ...

  8. C# Winform ListView实现单元格双击复制内容到剪贴板

    private void listView_MouseDoubleClick(object sender, MouseEventArgs e) { ListView listview = (ListV ...

  9. ListView中Item与Checkable子类控件抢焦点问题

    Android开发中,经常需要为ListView定制Adapter,绑定各种子类控件.如果Item包含Button等Checkable的控件,那么就会发生点击Item无法响应的问题.原因是自己定义的I ...

随机推荐

  1. javaSE第二十天

    第二十天    254 1:递归(理解)    254 (1)方法定义中调用方法本身的现象    254 (2)递归的注意事项    255 (3)递归的案例:    255 A:递归求阶乘    2 ...

  2. 深入了解Javascript模块化编程

    本文译自Ben Cherry的<JavaScript Module Pattern: In-Depth>.虽然个人不太认同js中私有变量存在的必要性,但是本文非常全面地介绍了Javascr ...

  3. c#桌面小软件

    这是以前练习时用c#做的桌面小软件,今天回顾下. 这是设计界面 可以看出该程序能够播放网络歌曲及浏览新闻. 实现:歌曲来源百度API,播放WindowsMediaPlayer api地址:string ...

  4. scribe日志分析工具安装

    系统CentOS6.2 x86_64 1.yum安装gcc,flex,m4,python/python-devel,ruby,libevent/libevent-devel,openssl/opens ...

  5. 设置peoplecode trace

    Configuring PeopleCode Trace Select PeopleTools, Utilities, Debug, Trace PeopleCode to access the Tr ...

  6. redis的lua使用(EVALSHA)

    redis 127.0.0.1:6379> SCRIPT LOAD "local list=redis.call('KEYS', KEYS[1] .. '*') return (tab ...

  7. 了解Unix进程(1)

    今天瞎看 看到一本了解Unix进程 -- 理解UNIX进程 的书 不错,可以看看,使用的ruby语言,第一章讲的是一些基础的知识 1.输出进程号和父进程号: puts Process.pid # 得到 ...

  8. LinkedList存储一副扑克牌,实现洗牌功能。

    package cd.itcast.runble; import java.util.LinkedList; import java.util.Random; /** * LinkedList存储一副 ...

  9. Mongodb Gridfs

    http://www.cnblogs.com/lipan/archive/2011/03/21/1989409.html

  10. xtrabackup之Innobackupex全备恢复

    一.当前环境 [mysql@hadoop1 ~]$ mysql --defaults-/my.cnf -uroot -p123456 -P3306 mysql> show variables l ...