having user thread update listViewItem.BackColor

Y

yancheng.cheok

Hello all,

I try to have user thread to perform update on the window form list
view item back color. However, I can see the new item was added each
time. However, the back color just not changed until I move the window
around. May I noe what code I had missing out?

Thank you very much!


delegate void OnGUIDelegate(int msgID, object param1, object
param2);
public void OnGUI(int msgID, object param1, object param2)
{
// Make sure we're on the right thread
if(listView1.InvokeRequired == false)
{
switch(msgID)
{
case GUIMessage.MSG_ERR:
if(param1 is string)
{
string strDate = DateTime.Now.ToLongTimeString();
string[] s = {strDate, (string)param1};

ListViewItem listViewItem = new ListViewItem(s);
listViewItem.StateImageIndex = 2;
listViewItem.BackColor = Color.FromArgb(255, 224, 192);

listView1.Items.Add(listViewItem);
isSave = false;
}
break;

case GUIMessage.MSG_INFO:
if(param1 is string)
{
string strDate = DateTime.Now.ToLongTimeString();
string[] s = {strDate, (string)param1};

ListViewItem listViewItem = new ListViewItem(s);
listViewItem.StateImageIndex = 0;
listViewItem.BackColor = Color.FromArgb(192, 255, 192);

listView1.Items.Add(listViewItem);
isSave = false;
}
break;

case GUIMessage.MSG_WARNING:
if(param1 is string)
{
string strDate = DateTime.Now.ToLongTimeString();
string[] s = {strDate, (string)param1};

ListViewItem listViewItem = new ListViewItem(s);
listViewItem.StateImageIndex = 1;
listViewItem.BackColor = Color.FromArgb(255, 255, 192);

listView1.Items.Add(listViewItem);
isSave = false;
}
break;
} // switch
}
else
{
// Update GUI asynchronously
OnGUIDelegate onGUI =
new OnGUIDelegate(OnGUI);
this.BeginInvoke(onGUI,
new object[] { msgID, param1, param2});
}
}
 
C

ClayB

Try calling listView1.Refresh() to see if that gives you what you
want. (Or maybe call listView1.Invalidate followed by
listView1.Update) .

=======================
Clay Burch
Syncfusion, Inc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top