下拉做過,日期沒做過,研究一下應該可以.
沒做過win的,如果是web,哪就用模板列來實現.

解决方案 »

  1.   

    将要在编辑时是下拉的普通列转化成模板列,将里面的textbox设成不可视,再放个DropDownList进去,跟着在DataGird的ItemDataBound事件中写
    if(e.Item.ItemIndex >= 0)
    {
    if(e.Item.ItemIndex == dgbaojia.EditItemIndex)
    {
                string a = ((TextBox)e.Item.FindControl("textbox的ID")).Text;
                DropDownList DDL = (DropDownList)e.Item.FindControl("DropDownList的ID");
                DDL.SelectedValue = a;            
              }
    }
      

  2.   

    using System;
    using System.Data;
    using System.Windows.Forms;
    using System.Drawing;
    namespace myControls
    {
    public class DataGridComboBoxColumn : DataGridColumnStyle 
    {
    private System.Windows.Forms.ComboBox   myComboBox = new ComboBox();
    private bool isEditing;
    private bool internalRaise=false; public DataGridComboBoxColumn() : base() 
    {
    myComboBox.Visible = false;
    myComboBox.DropDownStyle =ComboBoxStyle.DropDownList ; //默认是不可编辑,只可拉,如果真要编辑,则另外设置
    isEditing=false;
    myComboBox.Leave +=new EventHandler(myComboBox_Leave); } public ComboBox ComboBox
    {
    get{return myComboBox;}
    set{myComboBox=value;}
    } protected override void Abort(int rowNum)
    {
    myComboBox.SelectionChangeCommitted -=  new EventHandler(ValueChanged);
    isEditing = false;
    myComboBox.Hide ();
    Invalidate();
    } protected override bool Commit (CurrencyManager dataSource, int rowNum) 
    {
    myComboBox.SelectionChangeCommitted -=  new EventHandler(ValueChanged);
    myComboBox.Bounds = Rectangle.Empty;
             
    if (!isEditing)
    return true; isEditing = false; try 
    {
    object value = myComboBox.SelectedValue;
    SetColumnValueAtRow(dataSource, rowNum, value);

    catch (Exception ex) 
    {
    Abort(rowNum);
    return false;
    } Invalidate();
    return true;
    } protected override void Edit(CurrencyManager source, int rowNum,Rectangle bounds, bool readOnly,string instantText, bool cellIsVisible) 
    {
    object value = GetColumnValueAtRow(source, rowNum);
    if (cellIsVisible) 
    {
    myComboBox.Parent =this.DataGridTableStyle.DataGrid;
    myComboBox.Bounds =bounds;
    myComboBox.Size = new Size(this.Width, this.myComboBox.PreferredHeight);

    if (!this.internalRaise )
    myComboBox.SelectedValue  = value; //防止在事件中再次调用
    myComboBox.Visible = (cellIsVisible == true) && (readOnly == false);
    myComboBox.BringToFront();
    myComboBox.Focus ();
    myComboBox.SelectionChangeCommitted  +=  new EventHandler(ValueChanged);

    else 
    {
    myComboBox.SelectedValue  = value;
    myComboBox.Visible = false;
    } if (myComboBox.Visible)
    DataGridTableStyle.DataGrid.Invalidate(bounds);
    }
    protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum) 
    {
    Paint(g, bounds, source, rowNum, false);
    }
    protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, bool alignToRight) 
    {
    Paint( g,bounds,  source, rowNum, Brushes.Red, Brushes.Blue, alignToRight);
    }
    protected override void Paint( Graphics g, Rectangle bounds,CurrencyManager source, int rowNum,Brush backBrush, Brush foreBrush,bool alignToRight) 
    {
    object data = (object)  GetColumnValueAtRow(source, rowNum);
    Rectangle rect = bounds;
    g.FillRectangle(backBrush,rect);
    // rect.Offset(0, 2);
    // rect.Height -= 2;
    g.DrawString(data.ToString(), this.DataGridTableStyle.DataGrid.Font, foreBrush, rect);

    }
    protected override Size GetPreferredSize(Graphics g, object value) 
    {
    return new Size(100, myComboBox.PreferredHeight);
    } protected override int GetMinimumHeight() 
    {
    return myComboBox.PreferredHeight ;
    } protected override int GetPreferredHeight(Graphics g,object value) 
    {
    return myComboBox.PreferredHeight;
    }
    protected override void SetDataGridInColumn(DataGrid value) 
    {
    //base.SetDataGridInColumn(value);
    if (myComboBox.Parent != null) 
    {
    myComboBox.Parent.Controls.Remove (myComboBox);
    }
    if (value != null) 
    {
    value.Controls.Add(myComboBox);
    }

    } private void ValueChanged(object sender, EventArgs e) 
    {
    this.isEditing = true;
    this.internalRaise = true;
    base.ColumnStartedEditing(myComboBox);
    this.internalRaise  = false;
    } private void myComboBox_Leave(object sender, EventArgs e)
    {
    myComboBox.Hide ();
    }
    }
    }