感觉应该使用DataGridTextBoxColumn来设置,但是设置了DataGridTextBoxColumn的TextBox.ForeColor并没有反应,估计是别的属性,究竟如何,请大家指教,谢谢

解决方案 »

  1.   

    变成模板列<div style="???"><div>
      

  2.   

    ref:
    http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q745q
      

  3.   

    private void datagrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
        if(e.Item.ItemType != ListItemType.Header &&e.Item.ItemType != ListItemType.Footer)
    {
    e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='#ADD8E6'");
    e.Item.Attributes.Add("onmouseout","this.style.backgroundColor='#EBF2F9'");
    }
    }????
      

  4.   

    谢谢楼上的几位,我这里问的不是ASP.NET的,而是WinForm中如何设置,谢谢
      

  5.   

    WinForm中的比较复杂,要进行重画dataGrid的
      

  6.   

    我目前是这样,但还有问题
    象文本对齐等private void dataGrid1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
    DataGrid dg=(DataGrid)sender;
    int rowCount=((DataTable)dg.DataSource).Rows.Count;
    Rectangle rect; StringFormat sf=new StringFormat();
    sf.FormatFlags =StringFormatFlags.DirectionRightToLeft; Pen pen=new Pen(Color.Red,1); try
    {
    for (int i=10;i<rowCount;i++)
    {
    int v0 = (int)dg[i,1] % 10;
    int v1 = (int)dg[i,8] % 10; rect=dg.GetCellBounds(i,8);
    if (v0 > 5)
    {
    if (v0 + v1 == 15)
    {
    //e.Graphics.FillRectangle(new SolidBrush(Color.DarkKhaki),rect);
    e.Graphics.DrawRectangle(pen,rect);
    //e.Graphics.DrawString(dg[i,8].ToString(),Font,new SolidBrush(Color.Black),rect,sf);
    }
    }
    else
    {
    if (v0 != 0 && v0 + v1 == 10)
    {
    e.Graphics.DrawRectangle(pen,rect);
    //e.Graphics.FillRectangle(new SolidBrush(Color.DarkKhaki),rect);
    //e.Graphics.DrawString(dg[i,8].ToString(),Font,new SolidBrush(Color.Black),rect,sf);
    }
    }
    int k0 = (int)dg[i - 1,10] % 10;
    int k1 = (int)dg[i - 1,11] % 10;
    int k2 = (int)dg[i - 3,12] % 10;
    int k3 = (int)dg[i - 1,13] % 10;
    int k4 = System.Math.Abs((int)dg[i - 1,14]) % 10;
    string s = dg[i - 1,15].ToString(); if (v1 == k0)
    {
    rect=dg.GetCellBounds(i-1,10);
    e.Graphics.DrawRectangle(pen,rect);
    //e.Graphics.FillRectangle(new SolidBrush(Color.DarkSeaGreen),rect);
    //e.Graphics.DrawString(dg[i-1,10].ToString(),Font,new SolidBrush(Color.Black),rect,sf);
    }
    if (v1 == k1)
    {
    rect=dg.GetCellBounds(i-1,11);
    e.Graphics.DrawRectangle(pen,rect);
    //e.Graphics.FillRectangle(new SolidBrush(Color.DarkSeaGreen),rect);
    //e.Graphics.DrawString(dg[i-1,11].ToString(),Font,new SolidBrush(Color.Black),rect,sf);
    }
    if (v1 == k2)
    {
    rect=dg.GetCellBounds(i-3,12);
    e.Graphics.DrawRectangle(pen,rect);
    //e.Graphics.FillRectangle(new SolidBrush(Color.DarkSeaGreen),rect);
    //e.Graphics.DrawString(dg[i-3,12].ToString(),Font,new SolidBrush(Color.Black),rect,sf);
    }
    if (v1 == k3)
    {
    //dataGridView1.Rows[e.RowIndex - 1].Cells[13].Style.BackColor = Color.DarkSeaGreen;
    rect=dg.GetCellBounds(i-1,13);
    e.Graphics.DrawRectangle(pen,rect);
    //e.Graphics.FillRectangle(new SolidBrush(Color.DarkSeaGreen),rect);
    //e.Graphics.DrawString(dg[i-1,13].ToString(),Font,new SolidBrush(Color.Black),rect,sf);
    }
    if (v1 == k4)
    {
    rect=dg.GetCellBounds(i-1,14);
    e.Graphics.DrawRectangle(pen,rect);
    //e.Graphics.FillRectangle(new SolidBrush(Color.DarkSeaGreen),rect);
    //e.Graphics.DrawString(dg[i-1,14].ToString(),Font,new SolidBrush(Color.Black),rect,sf);
    } if (s.Length >0 && s.IndexOf(v1.ToString())<0)
    {
    rect=dg.GetCellBounds(i-1,15);
    e.Graphics.DrawRectangle(pen,rect);
    //e.Graphics.FillRectangle(new SolidBrush(Color.DarkSeaGreen),rect);
    //e.Graphics.DrawString(dg[i-1,15].ToString(),Font,new SolidBrush(Color.Black),rect,sf);
    }
    }
    }
    catch
    {
    //错误调试用
    }
    }
      

  7.   

    e.Items[0].Cells[0].BackColor=Color.FromName("#ffffff");
      

  8.   

    datagridview1.Columns[2].DefaultCellStyle.BackColor = Color.Red;
      

  9.   

    我在.Net 1.1下开发的,没有datagridview啊,哎,头大啊,而且我不是在Datagrid的事件中,所以也没有event
      

  10.   

    现在做开发,哪还有人用最基础的DataGrid控件?
    有多少现成的盗版DataGrid已经写好,操作简便,还要你自己写Pen来改变dataGrid的颜色么?你可以查下Farpoint Spread或者UltraGrid