以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. C puzzles详解【13-15题】

    第十三题 int CountBits(unsigned int x) { ; while(x) { count++; x = x&(x-); } return count; } 知识点讲解 位 ...

  2. Linux安装VritualBox实现虚拟机win2003端口映射 支持远程

    1. 使用VNC登录到Linux系统 2. 安装VritualBox 找到VritualBox的软件包 这里的是run格式的 可以直接在终端运行  需要几分钟时间 3.VritualBox新建虚拟机 ...

  3. C#获取本周周一的日期

    /// <summary> /// 获取本周的周一日期 /// </summary> /// <returns></returns> public st ...

  4. jquery Ajax中的dataType简析

    jquery中的ajax有好几种运用方式,但是基本上都是使用的$.ajax()方法,很多人经常会使用它来从后台获取json格式的数据,但是经常发现返回的json字符串并不能自动的转换成js里的json ...

  5. 各种数据处理方案(SQL,NoSQL,其他)的应用场景

    综合stackoverflow和linkin上的相关讨论,还有我个人的工作经验:   Redis应用场景(大部分场景下memcache可以用Redis代替,所以不单独讨论) 线上业务,读写的高性能要求 ...

  6. PHP四大安全策略

    PHP中的文件系统安全.数据库安全.用户数据安全等安全相关的问题. 一.文件系统安全 php如果具有root权限,且在脚本中允许用户删除文件,那么用户提交数据,不进行过滤,就非常有可能删除系统文件 & ...

  7. 解析 this.initialize.apply(this, arguments)

    一. 起因 那天用到prototype.js于是打开看看,才看几行就满头雾水,原因是对js的面向对象不是很熟悉,于是百度+google了一把,最后终于算小有收获,写此纪念一下^_^. prototyp ...

  8. FireFox Prevent this page from creating addtional dialogs 火狐浏览器 设置 阻止此页面创建更多对话框

    FireFox英文版本老弹出“Prevent this page from creating addtional dialogs”的确认框 FireFox english version alert ...

  9. for xml path('') 引发的数据不完整

    When you read Extensible Markup Language (XML) data from Microsoft SQL Server by using the SqlDataRe ...

  10. STM32F0xx_TIM基本延时配置详细过程

    前言 关于定时器大家都应该不会陌生,因为处理器都有这个功能.今天总结的F0系列芯片的定时器根据芯片型号不同,数量也不同.定时器分类:基本定时器.通用定时器和高级定时器.计数位数也有不同,有16位的,有 ...