DevExpress的gridcontrol样式问题

童话少年 2011-12-27 12:22:07
gridcontrol行获取焦点之后,怎么改变焦点行的样式
比如gridcontrol初始显示都是红色字体,当我几点某行的时候,被点击的这行字体变为黑色
这个样式要怎么写?
我知道怎么变黑色,但是每次都是全部变黑色了,不是我要的单行变黑
高手指教下
...全文
509 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
无常名 2011-12-29
  • 打赏
  • 举报
回复
已经发了
ijwsoft 2011-12-27
  • 打赏
  • 举报
回复
设置 gridview.OptionsSelection-->EnableAppearanceFocusedCell=false,EnableAppearanceFocusedRow=true

就OK了

如果你希望选中行的颜色是别的颜色:设置 gridview.Appearance --> FocusedRow-->BackColor,ForeColor
无常名 2011-12-27
  • 打赏
  • 举报
回复
我有一个DEV中文的简单使用说明,不知道有没有用,很久以前用过这个东西,都忘了。
要的话留一下邮箱,发给你。
狗血大熊猫 2011-12-27
  • 打赏
  • 举报
回复
下面的代码可以实现你的描述,有点事耽搁了。。。
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);
}
}
}
狗血大熊猫 2011-12-27
  • 打赏
  • 举报
回复
下面的代码可以实现你的描述,有点事耽搁了。。。
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);
}
}
}
狗血大熊猫 2011-12-27
  • 打赏
  • 举报
回复
下面的代码可以实现你的描述,不过你的要求很古怪
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);
}
}
}
童话少年 2011-12-27
  • 打赏
  • 举报
回复
终于搞定了,感谢7楼的提示
童话少年 2011-12-27
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 51crack 的回复:]
需要增加一个标志列,然后在CustomDrawCell中处理

VB.NET code

Private Sub AdvBandedGridView1_FocusedRowChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Hand……
[/Quote]

标识列的值赋不进去啊,怎么回事
童话少年 2011-12-27
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 lin0601 的回复:]
gridview的单击事件
[/Quote]

单击事件里面写不了
更改不了那行的样式
51Crack 2011-12-27
  • 打赏
  • 举报
回复
需要增加一个标志列,然后在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
小火龙果 2011-12-27
  • 打赏
  • 举报
回复
gridview的单击事件
童话少年 2011-12-27
  • 打赏
  • 举报
回复
自己定一下……
童话少年 2011-12-27
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 keenweiwei 的回复:]
设置 gridview.OptionsSelection-->EnableAppearanceFocusedCell=false,EnableAppearanceFocusedRow=true

就OK了

如果你希望选中行的颜色是别的颜色:设置 gridview.Appearance --> FocusedRow-->BackColor,ForeColor
[/Quote]

我漏说了一句,字体颜色改变之后要保存下来
意思就是我点击第一行之后,字体变黑,然后点击第二行的时候,第一行还是黑的,而不是变为红色
这个能实现么

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧