怎样在datagridview中显示图片???datagridview中怎样修改名称时让它显示成下拉列表框,直接进行选择

解决方案 »

  1.   

           private void dgvPackDetail_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
            {
                string picPath = @"....";
                System.IO.FileStream fs = new System.IO.FileStream(picPath, System.IO.FileMode.Open);
                Image im = Image.FromStream(fs);
                fs.Close();
                if (e.ColumnIndex == 0)
                {
                    e.Value = im;
                }
            }
      

  2.   


    路径这里有点不太明白啊,可以详细点不,加载的时候用dataset绑定,那这里的图片路径怎样获取好呢
      

  3.   

            private void DataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
            {
                if (e.Control is DataGridViewComboBoxEditingControl && this.DataGridView.CurrentCell.ColumnIndex == 4 && this.DataGridView.CurrentCell.RowIndex != -1)
                {
                    this.DataGridViewComboBox = (DataGridViewComboBoxEditingControl)e.Control;
                    DataGridViewComboBox.SelectionChangeCommitted += new EventHandler(this.DataGridViewComboBox_SelectionChangeCommitted);
                }
            }        private void DataGridViewComboBox_SelectionChangeCommitted(object sender, EventArgs e)
            {
                 ##你要做的事
                        }        private void DataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
            {
                if (this.DataGridViewComboBox != null)
                {
                    DataGridViewComboBox.SelectionChangeCommitted -= new EventHandler(this.DataGridViewComboBox_SelectionChangeCommitted);
                    this.DataGridViewComboBox = null;
                }
            }
      

  4.   

    private DataGridViewComboBoxEditingControl DataGridViewComboBox = null;5楼漏了一句
      

  5.   


    编辑datagridview时,不需要把 DataGridViewTextBoxColumn  换成DataGridViewComboBoxColumn吧
      

  6.   

    手动换一下,然后DataPropetyName绑定下源!反正我是这么搞定的
      

  7.   


     private void DataGridViewComboBox_SelectionChangeCommitted(object sender, EventArgs e)
      {
      ##你要做的事
      }
    这是个事件??????
      

  8.   

    这个是下拉框index改变了,驱动其他数据变化的事件啊 比如级联之类的
      

  9.   

    图片
    private void dataGridview1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)   
    {   
      if (dataGridview1.Columns[e.ColumnIndex].Name.Equals("Image"))   
      {   
      string path = e.Value.ToString();   
      e.Value = GetImage(path);   
      }   
    }   
    public System.Drawing.Image GetImage(string path)   
    {   
      System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open);   
      System.Drawing.Image result = System.Drawing.Image.FromStream(fs);     fs.Close();     return result;   }   
    使用DataGridViewImageColumn   
    DataGridViewImageColumn column = new DataGridViewImageColumn();   
    dataGridView1.Columns.Add(column);   
    column.HeaderText = "图片";   
    column.Image = System.Drawing.Image.FromFile("路径"); private void dataGridView1_EditingControlShowing(object sender,
      DataGridViewEditingControlShowingEventArgs e)
    {
      ComboBox combo = e.Control as ComboBox;
      if (combo != null)
      {
      combo.SelectedIndexChanged +=
      new EventHandler(ComboBox_SelectedIndexChanged);
      }
    }
    private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
    {
     ComboBox cb=(ComboBox)sender;
    }