0

I have list view that I use to display SMS from my GSM modem. I am reading the port for messages, parsing them and then displaying them. The format that I get when I read messages are:

+CMGL: 5,"REC READ","IA-612345","","2012/08/04 11:54:00+22"
Some text message

Code that I use to parse:

public ShortMessageCollection ParseMessages(string input)
{
    ShortMessageCollection messages = new ShortMessageCollection();
    Regex r = new Regex(@"\+CMGL: (\d+),""(.+)"",""(.+)"",(.*),""(.+)""\r\n(.+)\r\n");
    Match m = r.Match(input);
    while (m.Success)
    {
        ShortMessage msg = new ShortMessage();
        msg.Index = m.Groups[1].Value;
        msg.Status = m.Groups[2].Value;
        msg.Sender = m.Groups[3].Value;
        msg.Alphabet = m.Groups[4].Value;
        msg.Sent = m.Groups[5].Value;
        msg.Message = m.Groups[6].Value;
        messages.Add(msg);
        m = m.NextMatch();
    }
}
return messages;

The loop that I use to add messages to list view :

foreach (ShortMessage msg in objShortMessageCollection)
{
    ListViewItem item = new ListViewItem(new string[] { msg.Sender, msg.Message, msg.Sent, msg.Index });
    item.Tag = msg;
    lvwMessages.Items.Insert(0, item);
}

Now my requirement is when i add messages to listview, the messages which are unread(REC UNREAD) should be displayed in bold font and messages READ should be displayed in normal font. Is this possible? Please let me know the procedure.

Shiridish
  • 4,942
  • 5
  • 33
  • 64

1 Answers1

5
if (condition)
{
    item.Font = New Font(item.Font, FontStyle.Bold);
}
Paul Fleming
  • 24,238
  • 8
  • 76
  • 113
  • Great one. I dint know it was so simple. Thnaks :) – Shiridish Aug 08 '12 at 12:15
  • @ flem :Also please help in this- I have listview mouse doubleclick event. On double click, the selected item font should be made normal – Shiridish Aug 08 '12 at 12:30
  • @Cdeez. ListView has a `MouseDoubleClick` event. Subscribe to this and alter the item in the same was as my posted answer `item.Font = New Font(item.Font, FontStyle.Regular);` changing the style to `Regular`. – Paul Fleming Aug 08 '12 at 17:33