如何通过单元格的值在C#中使用SQLite数据库的更改特定数据网格单元格属性 [英] how to change particular data grid cell properties by the value of cell in c# with Sqlite database
本文介绍了如何通过单元格的值在C#中使用SQLite数据库的更改特定数据网格单元格属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新来的 C#
和数据库
链接,这就是为什么无法通过搜索的旧帖子得到这个< A HREF =http://www.stackoverflow.com>计算器
code像
私人无效bookDetails()
{
字符串connectionPath = @数据源=数据\ libraryData.dat;版本= 3;新= FALSE;的COM preSS =真;
使用(SQLiteConnection连接=新SQLiteConnection(connectionPath))
{
SQLiteCommand命令= connection.CreateCommand();
connection.Open();
查询字符串=SELECT bookno为登记号,书中code为ISBN号,标题作为标题,作者为作者,发行商为出版社,编辑为'版',storagehint为存储提示,描述为'说明'FROM booksDetails;
command.CommandText =查询;
command.ExecuteNonQuery();
SQLiteDataAdapter DA =新SQLiteDataAdapter(命令);
的DataSet ds为新的DataSet();
da.Fill(DS,booksDetails);
INT C = ds.Tables [booksDetails] Rows.Count。
dataGridView1.DataSource = ds.Tables [booksDetails];
dataGridView1.Sort(dataGridView1.Columns [ISBN编号],ListSortDirection.Ascending);
dataGridView1.ReadOnly = TRUE;
的Connection.close();
this.Totals.Text =总数书籍中的+ Convert.ToString(C);
}
}
我用像上面得到一些图书馆的书的细节,现在我想突出显示特定的细胞或没有价值改变其颜色。本书或任何其他的。
pferred样品code $ P $
在此先感谢...
解决方案
私人无效dataGridView1_CellFormatting(对象发件人,DataGridViewCellFormattingEventArgs E)
{
颜色C = Color.Black;
如果(e.ColumnIndex == 6)
{
如果(iSlate的(Convert.ToString(e.Value)))
C = Color.Red;
}
e.CellStyle.ForeColor = C; //或e.CellStyle.BackColor = C;任何你可以做这样的
}
和code事件是
this.dataGridView1.CellFormatting + =新System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.dataGridView1_CellFormatting);
这将在 yourform.designer.cs
被自动生成的,否则你手动添加
I am new to c#
and Database
linking that's why not able to get this by searching old posts of stackoverflow
Code like
private void bookDetails()
{
string connectionPath = @"Data Source=Data\libraryData.dat;Version=3;New=False;Compress=True";
using (SQLiteConnection connection = new SQLiteConnection(connectionPath))
{
SQLiteCommand command = connection.CreateCommand();
connection.Open();
string query = "SELECT bookno as 'Book No.', bookCode as 'ISBN No.', title as 'Title', author as 'Author', publisher as 'Publishers', edition as 'Edition', storagehint as 'Storage Hint', description as 'Description' FROM booksDetails";
command.CommandText = query;
command.ExecuteNonQuery();
SQLiteDataAdapter da = new SQLiteDataAdapter(command);
DataSet ds = new DataSet();
da.Fill(ds, "booksDetails");
int c = ds.Tables["booksDetails"].Rows.Count;
dataGridView1.DataSource = ds.Tables["booksDetails"];
dataGridView1.Sort(dataGridView1.Columns["ISBN No."], ListSortDirection.Ascending);
dataGridView1.ReadOnly = true;
connection.Close();
this.Totals.Text = "Total No. of Books Found : "+ Convert.ToString(c);
}
}
i used like above for getting some library book details, now i want highlight a particular cell or change its color by the value of no. of book or any other..
sample code preferred
thanks in advance...
解决方案
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
}
and code for event is
this.dataGridView1.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.dataGridView1_CellFormatting);
this will be auto generated in yourform.designer.cs
or else you add it manually
这篇关于如何通过单元格的值在C#中使用SQLite数据库的更改特定数据网格单元格属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文