Answer the question
In order to leave comments, you need to log in
How to keep selected row color after updating data from Mysql database?
Hello, I ask for your help. There is this C# code:
Dictionary<int, Color> colorsList = new Dictionary<int, Color>();
private void toolStripButton5_Click(object sender, EventArgs e)//ИЗМЕНЕНИЕ ЦВЕТА СТРОКИ
{
for (int i = 0; i < listView1.Items.Count; i++)
{
if (listView1.Items[i].Selected == true)
{
if (toolStripComboBox1.Text == "Красный")
{
listView1.Items[i].BackColor = Color.Red;
if (!colorsList.ContainsKey(i)) { colorsList.Add(i, Color.Red); }
else { colorsList[i] = Color.Red; }
}
else if (toolStripComboBox1.Text == "Желтый")
{
listView1.Items[i].BackColor = Color.Yellow;
if (!colorsList.ContainsKey(i)) { colorsList.Add(i, Color.Yellow); }
else { colorsList[i] = Color.Yellow; }
}
else if (toolStripComboBox1.Text == "Зеленый")
{
listView1.Items[i].BackColor = Color.Green;
if (!colorsList.ContainsKey(i)) { colorsList.Add(i, Color.Green); }
else { colorsList[i] = Color.Green; }
}
else if (toolStripComboBox1.Text == "Без цвета")
{
listView1.Items[i].BackColor = Color.White;
if (!colorsList.ContainsKey(i)) { colorsList.Add(i, Color.White); }
else { colorsList[i] = Color.White; }
}
}
}
}
void SetColor()
{
foreach (var c in colorsList)
{
if (listView1.Items.Count >= c.Key)
listView1.Items[c.Key].BackColor = c.Value;
}
}
private async void toolStripButton4_Click(object sender, EventArgs e)//ОБНОВЛЕНИЕ ДАННЫХ
{
listView1.Items.Clear();
await LoadBanksAsync();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question