gridcontrol行获取焦点之后,怎么改变焦点行的样式
比如gridcontrol初始显示都是红色字体,当我几点某行的时候,被点击的这行字体变为黑色
这个样式要怎么写?
我知道怎么变黑色,但是每次都是全部变黑色了,不是我要的单行变黑
高手指教下

解决方案 »

  1.   

    我有一个DEV中文的简单使用说明,不知道有没有用,很久以前用过这个东西,都忘了。
    要的话留一下邮箱,发给你。
      

  2.   

    设置 gridview.OptionsSelection-->EnableAppearanceFocusedCell=false,EnableAppearanceFocusedRow=true就OK了如果你希望选中行的颜色是别的颜色:设置 gridview.Appearance --> FocusedRow-->BackColor,ForeColor
      

  3.   

    需要增加一个标志列,然后在CustomDrawCell中处理    Private Sub AdvBandedGridView1_FocusedRowChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles AdvBandedGridView1.FocusedRowChanged
            AdvBandedGridView1.SetFocusedRowCellValue(标志列, "1")
        End Sub    Private Sub AdvBandedGridView1_CustomDrawCell(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs) Handles AdvBandedGridView1.CustomDrawCell
            If AdvBandedGridView1.GetRowCellValue(e.RowHandle, 标志列) = "1" Then
                e.Appearance.ForeColor = Color.Black
            End If
        End Sub
      

  4.   

    下面的代码可以实现你的描述,不过你的要求很古怪 
       public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        DataTable dt = null;
            List<int> lst = null;        private void Form1_Load(object sender, EventArgs e)
            {
                this.gridView1.OptionsBehavior.Editable = false;
                this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;
                this.gridView1.OptionsSelection.EnableAppearanceFocusedRow = false;            dt = new DataTable();
                dt.Columns.Add("colname", typeof(string)).Caption = "姓名";
                dt.Columns.Add("colid", typeof(string)).Caption = "学号";            dt.Rows.Add("张三", "201101");
                dt.Rows.Add("李四", "201102");
                dt.Rows.Add("王五", "201103");            this.gridControl1.DataSource = dt;            this.gridView1.FocusedRowHandle = -1;
                lst = new List<int>();
            }
            private void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
            {
                if (lst.Contains(e.RowHandle))
                {
                    e.Appearance.ForeColor = Color.Red;
                }
            }        private void gridView1_MouseDown(object sender, MouseEventArgs e)
            {
                DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hi = this.gridView1.CalcHitInfo(e.Location);
                if (hi.InRow == false)
                {
                    return;
                }
                int rowhandle = hi.RowHandle;
                if (!lst.Contains(rowhandle))
                {
                    lst.Add(rowhandle);
                }
            }
        }
      

  5.   

    下面的代码可以实现你的描述,有点事耽搁了 
       public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        DataTable dt = null;
            List<int> lst = null;        private void Form1_Load(object sender, EventArgs e)
            {
                this.gridView1.OptionsBehavior.Editable = false;
                this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;
                this.gridView1.OptionsSelection.EnableAppearanceFocusedRow = false;            dt = new DataTable();
                dt.Columns.Add("colname", typeof(string)).Caption = "姓名";
                dt.Columns.Add("colid", typeof(string)).Caption = "学号";            dt.Rows.Add("张三", "201101");
                dt.Rows.Add("李四", "201102");
                dt.Rows.Add("王五", "201103");            this.gridControl1.DataSource = dt;            this.gridView1.FocusedRowHandle = -1;
                lst = new List<int>();
            }
            private void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
            {
                if (lst.Contains(e.RowHandle))
                {
                    e.Appearance.ForeColor = Color.Red;
                }
            }        private void gridView1_MouseDown(object sender, MouseEventArgs e)
            {
                DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hi = this.gridView1.CalcHitInfo(e.Location);
                if (hi.InRow == false)
                {
                    return;
                }
                int rowhandle = hi.RowHandle;
                if (!lst.Contains(rowhandle))
                {
                    lst.Add(rowhandle);
                }
            }
        }
      

  6.   

    下面的代码可以实现你的描述,有点事耽搁了 
       public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        DataTable dt = null;
            List<int> lst = null;        private void Form1_Load(object sender, EventArgs e)
            {
                this.gridView1.OptionsBehavior.Editable = false;
                this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;
                this.gridView1.OptionsSelection.EnableAppearanceFocusedRow = false;            dt = new DataTable();
                dt.Columns.Add("colname", typeof(string)).Caption = "姓名";
                dt.Columns.Add("colid", typeof(string)).Caption = "学号";            dt.Rows.Add("张三", "201101");
                dt.Rows.Add("李四", "201102");
                dt.Rows.Add("王五", "201103");            this.gridControl1.DataSource = dt;            this.gridView1.FocusedRowHandle = -1;
                lst = new List<int>();
            }
            private void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
            {
                if (lst.Contains(e.RowHandle))
                {
                    e.Appearance.ForeColor = Color.Red;
                }
            }        private void gridView1_MouseDown(object sender, MouseEventArgs e)
            {
                DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hi = this.gridView1.CalcHitInfo(e.Location);
                if (hi.InRow == false)
                {
                    return;
                }
                int rowhandle = hi.RowHandle;
                if (!lst.Contains(rowhandle))
                {
                    lst.Add(rowhandle);
                }
            }
        }