TotalInsanity
Programmer
I have created a listview in my C# form and when I add an item through my code I change the background colour of my cells/rows. However, when I move over them at runtime with my mouse, the colour defaults back to white and then they stay white (when they should be red!).
The highlighted one is ok however (when clicking with mouse), it's just the background colour rows I have changed that are a problem. They are displayed with a red background colour when the form is displayed and when I move my mouse over the form they are OK. They vanish when I move my mouse over the listview control???
Is this simply a glitch in VS? I have no idea how to fix it, Can anyone help me out please??
When I enter items into the listview I am using the following code.
any help at all would be vastly appreciated!
The highlighted one is ok however (when clicking with mouse), it's just the background colour rows I have changed that are a problem. They are displayed with a red background colour when the form is displayed and when I move my mouse over the form they are OK. They vanish when I move my mouse over the listview control???
Is this simply a glitch in VS? I have no idea how to fix it, Can anyone help me out please??
When I enter items into the listview I am using the following code.
Code:
//get messages
DataTable dTable = this.m_mainToolbarForm.AllMessagesDataSet.Tables["Table"];
// Clear the ListView control
listBox1.Items.Clear();
// Attach Subitems to the ListView
listBox1.Columns.Add("Priority", 50, HorizontalAlignment.Center);
listBox1.Columns.Add("Message Title", 220, HorizontalAlignment.Left);
listBox1.Columns.Add("Date", 120, HorizontalAlignment.Left);
// Display items in the ListView control
for (int i = 0; i < dTable.Rows.Count; i++)
{
DataRow drow = dTable.Rows[i];
// Only row that have not been deleted
if (drow.RowState != DataRowState.Deleted)
{
// Add a ListItem object to the ListView.
ListViewItem messageItem = listBox1.Items.Add(drow["Message_Priority"].ToString());
messageItem.UseItemStyleForSubItems = false;
// Add the message title subitem.
ListViewItem.ListViewSubItem messageTitle = messageItem.SubItems.Add(drow["Message_Title"].ToString());
// Add the message date subitem.
ListViewItem.ListViewSubItem messageDate = messageItem.SubItems.Add(drow["Message_Added"].ToString());
//check if message high priority or not and highlight accordingly
if (drow["Message_Priority"].ToString() == "1")
{
messageItem.BackColor = Color.Red;
messageTitle.BackColor = Color.Red;
messageDate.BackColor = Color.Red;
}
else
{
messageItem.BackColor = Color.White;
messageTitle.BackColor = Color.White;
messageDate.BackColor = Color.White;
}
}
}
any help at all would be vastly appreciated!