C# 在通知弹出窗口的datagridview中显示所选行
使用c#、winforms、sqlite datagridview有name、startdate、expirationdate列 我有一个应用程序,用户点击一个按钮,点击事件将取其中一列中的expirationdate,并从今天的日期减去它,如果数字小于61(必须小于),则该行将变亮。基本上,它会突出显示日期接近今天日期的行。现在我想要一个弹出窗口,显示高亮显示的行的“name”列,但我不确定如何继续。如果我是对的,我需要把它放到for循环中,然后使用If-case,也许C# 在通知弹出窗口的datagridview中显示所选行,c#,datagridview,C#,Datagridview,使用c#、winforms、sqlite datagridview有name、startdate、expirationdate列 我有一个应用程序,用户点击一个按钮,点击事件将取其中一列中的expirationdate,并从今天的日期减去它,如果数字小于61(必须小于),则该行将变亮。基本上,它会突出显示日期接近今天日期的行。现在我想要一个弹出窗口,显示高亮显示的行的“name”列,但我不确定如何继续。如果我是对的,我需要把它放到for循环中,然后使用If-case,也许 for
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string test = ds.Tables[0].Rows[i]["ExpirationDate"].ToString();
if(test != "")
{
DateTime expiraryDate = Convert.ToDateTime(test); //convert string to datetime
DateTime itoday = DateTime.Today; //get current date
DateTime today = Convert.ToDateTime(itoday); //convert string to datetime
// String daysdiffstring = (expiraryDate - today).TotalDays.ToString();
int daysdiffstring = expiraryDate.Subtract(today).Days;
string daysdifffstring = Convert.ToString(daysdiffstring);
int daysdiff = Convert.ToInt32(daysdiffstring);
if (daysdiff < 61 && daysdiff >= -1) //2 months close to expiry dangerous
{
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Red;
dataGridView1.Rows[i].DefaultCellStyle.ForeColor = Color.Black;
}
}
PopupNotifier popup = new PopupNotifier();
popup.Image = Properties.Resources.information_icon;
popup.TitleText = "Notification on ending certificates";
popup.ContentText = "hello world"; //replace this
popup.Popup();
for(int i=0;i=-1)//2个月接近到期危险
{
dataGridView1.Rows[i].DefaultCellStyle.BackColor=Color.Red;
dataGridView1.Rows[i].DefaultCellStyle.ForeColor=Color.Black;
}
}
PopupNotifier popup=新的PopupNotifier();
popup.Image=Properties.Resources.information_图标;
popup.TitleText=“证书终止通知”;
popup.ContentText=“hello world”//替换此
popup.popup();
您需要在for和if语句中添加适当的代码
for (int i = 0; i<ds.Tables[0].Rows.Count; i++)
{
var nearToExpiryUsers = new List<string>();
----
Your code
----
if (daysdiff< 61 && daysdiff >= -1) //2 months close to expiry dangerous
{
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Red;
dataGridView1.Rows[i].DefaultCellStyle.ForeColor = Color.Black;
nearToExpiryUsers.Add(ds.Tables[0].Rows[i]["name"]);
}
}
抱歉,您所说的“在nearToExpiryUsers中遍历每个字符串以创建格式化字符串”是什么意思我在ExpiryUsers附近使用了一个变量,该变量将包含即将过期的用户列表。现在您可以选择格式化和显示。我使用了Environment.NewLine,以便在显示时弹出窗口将有一个垂直的用户名列表。即,从新行开始。您不能直接将列表分配给popup.ContextText。
foreach (var expiredName in expiredNames)
{
popup.ContentText += expiredName + Environment.NewLine;
}