我的“信使”应用程序需要帮助。所有消息都显示在DGV中。我需要有“新消息”FontStyle.Bold。我比较日志和DGV,如果spravaDGV!= spravaLOGY然后DGV FontStyle.bold,但它不起作用
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
citat.Text = "Správa od: " + row.Cells["pc"].Value.ToString() + Environment.NewLine + "Dátum a čas: " + row.Cells["datum"].Value.ToString()
+ Environment.NewLine + Environment.NewLine + "Správa:" + Environment.NewLine + row.Cells["sprava"].Value.ToString();
spravaDGV = row.Cells["sprava"].Value.ToString();
nacitanie_logu();
zapisanie_logu();
if (spravaDGV != spravaLOGY)
{
DataGridViewCellStyle style = new DataGridViewCellStyle();
style.Font = new Font(dataGridView1.Font, FontStyle.Bold);
dataGridView1.Rows[0].DefaultCellStyle = style;
}
}
}
投入日志:
private void zapisanie_logu()
{
string constring = "Server=***;Database=OitDB;Uid=martin;Pwd=;";
string Query = "INSERT INTO OitDB.logy(pc,sprava)VALUES(@pc,@sprava)";
MySqlConnection conDatabase = new MySqlConnection(constring);
MySqlCommand cmdDatabase = new MySqlCommand(Query, conDatabase);
cmdDatabase.Parameters.AddWithValue("@sprava", spravaDGV);
cmdDatabase.Parameters.AddWithValue("@pc", nazovPC);
MySqlDataReader myReader;
try
{
conDatabase.Open();
myReader = cmdDatabase.ExecuteReader();
MessageBox.Show("Správa odoslaná!");
while (myReader.Read())
{
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
从日志中选择:
string spravaLOGY;
private void nacitanie_logu()
{
MySqlConnection mcon = new MySqlConnection("Server=***;Database=OitDB;Uid=martin;Pwd=;");
string s = "select sprava from logy where pc=@pc";
mcon.Open();
MySqlCommand mcd = new MySqlCommand(s, mcon);
mcd.Parameters.AddWithValue("@pc", nazovPC);
MySqlDataReader mdr = mcd.ExecuteReader();
while (mdr.Read())
{
spravaLOGY = mdr.GetString("sprava");
}
}
插入,选择和调整工作正常但改变fontstyle不起作用。你有什么解决方案吗? THX。