求助vc中如何给DataGrid的指定行设置颜色
假定DataGrid的某一字段为flag,当某行的flag为1时,这一行就显示为蓝色
当flag为0时,这一行就显示为灰色。根据这样的规则给所有行加上颜色。
我知道给整体设置背景色是用SetBackColor
但是不知如何得到每行的那个flag值,并且如何给这行设置颜色
谢谢

解决方案 »

  1.   


    没用过那个控件。不过系统带的 List Ctrl 控件可以做到。
      

  2.   

    谢谢回复
    不过我想用DataGrid来实现
    不知道,有没有方法
      

  3.   

     m_Grid.SetRedraw(FALSE);    // Get the current selection    int NextRow = m_Grid.GetRowSel();    // If the position is at the last record, return
        if(NextRow <= 1)
        {
            return;
        }
        else
        {
            long BackColor[2],FontColor[2];        int Column;        // The BackColor and the FontColor variables 
            // are manipulated because we want a 
            // selected effect to be given to the previous
            // record. Here, we are merely changing 
            // the color of the selected
            // row to give it that effect.        BackColor[0] = 0x00FFFFFF;
            BackColor[1] = 0x00FFFFB0;        FontColor[0] = 0x00400000;
            FontColor[1] = 0x000000FF;        for(Column = 1; Column < m_Grid.GetCols(); Column++)
            {
                m_Grid.SetCol(Column);
                m_Grid.SetCellBackColor(BackColor[0]);
                m_Grid.SetCellForeColor(FontColor[0]);
            }
            m_Grid.SetRow(--NextRow);        for(Column = 1; Column < m_Grid.GetCols(); Column++)
            {
                m_Grid.SetCol(Column);
                m_Grid.SetCellBackColor(BackColor[1]);
                m_Grid.SetCellForeColor(FontColor[1]);
            }        m_Grid.Refresh();
            m_Grid.SetRedraw(TRUE);
        }看看这种方法行不行!
      

  4.   

    C#例子,自己翻译一下:
    http://www.codeproject.com/csharp/custom_datagridcolumnstyl.asp
      

  5.   

    shanhqk 
    你的代码是vc++的吗
    我刚运行了下,编译出错。
    提示有的函数不是CDataGrid的成员函数
    在vc下的相应函数是什么呢?
    我不清楚
      

  6.   

    不好意思,上面的例子是msflexgrid的
    这个里面有例子,LZ可以试试。
    http://www.codeproject.com/miscctrl/DataGridControl.asp
      

  7.   

    感谢shanhqk和dyw的回复
    dyw的c#代码,我还要翻译一下,有一定的难度,因为对应的函数我都不熟悉。
    shanhqk提供的例子我看了,需要消化一阵子,因为这个代码挺大的,对话框都是
    自己生成的,许多函数也是自己定义的,没有用vc的DataGrid控件,是纯代码生成的。
    不知有没有用vc的DataGrid控件的例子,设置指定行的颜色?
      

  8.   

    俄,属性->split中的marqueestyle,可以改变选中行的颜色
      

  9.   

    shakaqrj 我是想用代码实现的,根据每行的flag值设置这行的颜色
      

  10.   

    关于vc6.0中datagrid能够实现拖动列的功能,我都砸了几百分了,还是一无所获
    不过今天终于实现了,哈哈
      

  11.   

    我也有类似的问题哦,我想用DataGrid手动添加行的数据,我不将它绑到数据源上,不知道怎么弄,楼主知道怎么弄吗
      

  12.   

    yuyanjun340
    你的问题我没太懂,DataGrid不就是要连接到数据库上的吗苦等我的问题的答案  
      

  13.   

    搞编程技术,VC++,C#,JAVA,VB,可以加QQ群251623
      

  14.   

    http://topic.csdn.net/u/20071031/11/60e8c6ff-0769-48a3-a8bc-f50499c8538a.html
    看看老大的回复
      

  15.   

    he很好,怎么得到 datagrid的行数