Pregunta

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.

¿Fue útil?

Solución

if (condition)
{
    item.Font = New Font(item.Font, FontStyle.Bold);
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top