如何使用Sqlite数据库通过c#中的单元格值更改特定数据网格单元格属性

如何使用Sqlite数据库通过c#中的单元格值更改特定数据网格单元格属性,c#,.net,winforms,sqlite,C#,.net,Winforms,Sqlite,我对c#和Database链接是新手,这就是为什么不能通过搜索 代码式 我用上面的方法来获取一些图书馆图书的详细信息,现在我想突出显示一个特定的单元格,或者通过“图书编号”或任何其他值来更改其颜色 样本代码优先 先谢谢你 private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { Color c = Color.Black;

我对
c#
Database
链接是新手,这就是为什么不能通过搜索

代码式 我用上面的方法来获取一些图书馆图书的详细信息,现在我想突出显示一个特定的单元格,或者通过“图书编号”或任何其他值来更改其颜色

样本代码优先

先谢谢你

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
        Color c = Color.Black;
        if (e.ColumnIndex == 6)
        {
            if (isLate(Convert.ToString(e.Value)))
                c = Color.Red;
        }
        e.CellStyle.ForeColor = c; // or e.CellStyle.BackColor= c; whatever you can do like this

    }
事件的代码是

this.dataGridView1.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.dataGridView1_CellFormatting);
这将在
yourform.designer.cs中自动生成,或者手动添加

事件的代码是

this.dataGridView1.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.dataGridView1_CellFormatting);

这将在yourform.designer.cs中自动生成,或者手动添加它

您需要在datagridview中循环行,然后将颜色设置为适当的行

假设颜色根据某种条件发生变化

private void myDataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  {
   int colIndex = e.ColumnIndex;
   int rowIndex = e.RowIndex;

   if (rowIndex >= 0 && colIndex >= 0)
   {
    DataGridViewRow myRow = dataGridView1.Rows[rowIndex];
    if (myRow.Cells[colIndex].Value.ToString() == "High")
    myRow.DefaultCellStyle.BackColor = Color.Red;
   }
  }

您需要遍历datagridview中的行,然后将颜色设置为适当的行

假设颜色根据某种条件发生变化

private void myDataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  {
   int colIndex = e.ColumnIndex;
   int rowIndex = e.RowIndex;

   if (rowIndex >= 0 && colIndex >= 0)
   {
    DataGridViewRow myRow = dataGridView1.Rows[rowIndex];
    if (myRow.Cells[colIndex].Value.ToString() == "High")
    myRow.DefaultCellStyle.BackColor = Color.Red;
   }
  }

您使用的是wpf还是winforms?-对于webforms-对于winforms我也得到了答案,下面的代码对我很有用谢谢@kshitij Mehtaare您使用wpf还是winforms?-对于webforms-对于WinForms,我也得到了答案,下面的代码对我很有用谢谢@kshitij Mehtathis也可以,但我想通过它的一个值来更改单元格属性,无论如何,谢谢。这也可以,但我想通过它的一个值来更改单元格属性,无论如何,谢谢