.net dataGridView 的使用。看看能不能不能实现 winform中:dateGridView 绑定数据后,1.每行数据库向上或向下滚动显示?2.根据里面某个字段,可以每行的颜色可以控制?可不可以实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 滚动显示:for (int i = 0; i < grdView.Rows.Count; i++) { grdView.FirstDisplayedScrollingRowIndex = i; }控制颜色:DataGridViewRow row = this.grdView.Rows[selectIndex]; if ((bool)row.Cells["colReviewed"].Value) { row.DefaultCellStyle.BackColor = Color.LightGreen; } else { row.DefaultCellStyle.BackColor = Color.White; } if (row.Cells["colIsMask"].Value.ToString().ToLower() == "true") { row.Cells["colIsMask"].Style.BackColor = Color.Red; } else { row.Cells["colIsMask"].Style.BackColor = isReviewEnd ? Color.LightGreen : Color.White; } 这两个看看,对你有帮助的http://hi.baidu.com/wowo2jia/blog/item/7cbe0d7c577014ec0ad187a7.htmlhttp://blog.csdn.net/chyocean/article/details/2062684 private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) { string title = ""; if (e.RowIndex >= 0) { try { title = dataGridView1.Rows[e.RowIndex].Cells["Title"].Value.ToString(); } catch { title = ""; } } if (title == "002") dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightGray; } 对于第一点,lz可以看看6楼提供的方法,很好!对于第二点,再来一个方法:private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e){ try { if (e.ColumnIndex == 1) //控制要格式化的列 { bool b = Convert.ToBoolean(dataGridView1.CurrentRow.Cells[e.ColumnIndex].Value); if(b) dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightGray; } } catch (System.Exception ex) { } } 求教Winfrom多线程与UI响应问题 Console.write C# UITypeEditor 问题 如何把2个数组拼接为一个数组? C#中有线程局部存储吗? 问个随机数问题 寻求ASP.NET防止文件下载最好的解决方法.无需通过IIS. WINDOWS应用程序添加配置文件的问题 C#编辑Excel 急!我想将pictureBox1里的图片保存到数据库111的表TABLE2中,列名为照片,类型为image,图片为.jpg文件,该怎么办?谢谢 关于《C#入门经典》中某处的疑问 为什么DataGridview的combobox下拉时背景就变黑了
for (int i = 0; i < grdView.Rows.Count; i++)
{
grdView.FirstDisplayedScrollingRowIndex = i;
}控制颜色:
DataGridViewRow row = this.grdView.Rows[selectIndex];
if ((bool)row.Cells["colReviewed"].Value)
{
row.DefaultCellStyle.BackColor = Color.LightGreen;
}
else
{
row.DefaultCellStyle.BackColor = Color.White;
} if (row.Cells["colIsMask"].Value.ToString().ToLower() == "true")
{
row.Cells["colIsMask"].Style.BackColor = Color.Red;
}
else
{
row.Cells["colIsMask"].Style.BackColor = isReviewEnd ? Color.LightGreen : Color.White;
}
http://hi.baidu.com/wowo2jia/blog/item/7cbe0d7c577014ec0ad187a7.html
http://blog.csdn.net/chyocean/article/details/2062684
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
string title = "";
if (e.RowIndex >= 0)
{
try
{
title = dataGridView1.Rows[e.RowIndex].Cells["Title"].Value.ToString();
}
catch { title = ""; }
}
if (title == "002")
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightGray;
}
对于第二点,再来一个方法:private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
try
{
if (e.ColumnIndex == 1) //控制要格式化的列
{
bool b = Convert.ToBoolean(dataGridView1.CurrentRow.Cells[e.ColumnIndex].Value);
if(b)
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightGray;
}
}
catch (System.Exception ex)
{
}
}