Click here to Skip to main content
15,921,226 members
Home / Discussions / C#
   

C#

 
GeneralRe: select datarows by using keys enum Pin
Xmen Real 12-Oct-08 8:17
professional Xmen Real 12-Oct-08 8:17 
QuestionListBox Colours Pin
Alex Grose12-Oct-08 7:31
Alex Grose12-Oct-08 7:31 
AnswerRe: ListBox Colours Pin
Xmen Real 12-Oct-08 7:54
professional Xmen Real 12-Oct-08 7:54 
AnswerRe: ListBox Colours Pin
DaveyM6912-Oct-08 8:11
professionalDaveyM6912-Oct-08 8:11 
GeneralRe: ListBox Colours Pin
Alex Grose12-Oct-08 9:25
Alex Grose12-Oct-08 9:25 
GeneralRe: ListBox Colours Pin
DaveyM6912-Oct-08 9:37
professionalDaveyM6912-Oct-08 9:37 
GeneralRe: ListBox Colours Pin
Alex Grose12-Oct-08 9:46
Alex Grose12-Oct-08 9:46 
GeneralRe: ListBox Colours Pin
DaveyM6912-Oct-08 23:04
professionalDaveyM6912-Oct-08 23:04 
You should be able to make it work from what I gave you before. I've expanded it a little to help.
This works for me given your scenario - you should be able to adapt it to suit your existing code.

A basic Feed class:
public class Feed
{
    public Feed(string displayText)
    {
        m_DisplayText = displayText;
        isNew = true;
    }
    private string m_DisplayText;
    private bool isNew;
    public string DisplayText
    {
        get { return m_DisplayText; }
    }
    public bool IsNew
    {
        get { return isNew; }
    }
    public void SetRead()
    {
        isNew = false;
    }
    public override string ToString()
    {
        return m_DisplayText;
    }
}

This inside the class that holds the ListBox (lstFeeds) and call FillList() after any default initialization.
private Color unreadForeColor = SystemColors.Window;
private Color unreadBackColor = SystemColors.ControlText;
[DefaultValue(typeof(Color), "Window")]
public Color UnreadForeColor
{
    get { return unreadForeColor; }
    set { unreadForeColor = value; }
}
[DefaultValue(typeof(Color), "ControlText")]
public Color UnreadBackColor
{
    get { return unreadBackColor; }
    set { unreadBackColor = value; }
}
private void FillList()
{
    lstFeeds.DrawMode = DrawMode.OwnerDrawFixed;
    lstFeeds.SelectedIndexChanged += new EventHandler(lstFeeds_SelectedIndexChanged);
    lstFeeds.DrawItem += new DrawItemEventHandler(lstFeeds_DrawItem);
    Feed[] feeds = new Feed[] {
        new Feed("Feed A"),
        new Feed("Feed B"),
        new Feed("Feed C"),
        new Feed("Feed D")};
    lstFeeds.Items.AddRange(feeds);
}
void lstFeeds_SelectedIndexChanged(object sender, EventArgs e)
{
    if (lstFeeds.SelectedIndices.Count > 0)
    {
        foreach (int selectedIndex in lstFeeds.SelectedIndices)
        {
            Feed selectedFeed = (Feed)lstFeeds.Items[selectedIndex];
            selectedFeed.SetRead();
        }
    }
}
void lstFeeds_DrawItem(object sender, DrawItemEventArgs e)
{
    Feed thisItem = (Feed)lstFeeds.Items[e.Index];
    if (thisItem.IsNew)
    {
        e = new DrawItemEventArgs(
            e.Graphics,
            e.Font,
            e.Bounds,
            e.Index,
            e.State,
            UnreadForeColor,
            UnreadBackColor);
    }
    e.DrawBackground();
    if (sender is ListBox)
    {
        ListBox listBox = (ListBox)sender;
        e.Graphics.DrawString(
            listBox.Items[e.Index].ToString(),
            e.Font,
            new SolidBrush(e.ForeColor),
            e.Bounds);
    }
}


Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

QuestionHelp With Sorting Multiple dataGridView Columns Pin
That Asian Guy12-Oct-08 6:24
That Asian Guy12-Oct-08 6:24 
AnswerRe: Help With Sorting Multiple dataGridView Columns Pin
DaveyM6912-Oct-08 7:06
professionalDaveyM6912-Oct-08 7:06 
GeneralRe: Help With Sorting Multiple dataGridView Columns Pin
That Asian Guy12-Oct-08 7:17
That Asian Guy12-Oct-08 7:17 
QuestionHTML code to string Pin
Alex Grose12-Oct-08 4:38
Alex Grose12-Oct-08 4:38 
AnswerRe: HTML code to string Pin
Guffa12-Oct-08 6:22
Guffa12-Oct-08 6:22 
GeneralRe: HTML code to string Pin
Alex Grose12-Oct-08 7:29
Alex Grose12-Oct-08 7:29 
QuestionBasic mp3/media player problem :( Pin
jas0n2312-Oct-08 4:23
jas0n2312-Oct-08 4:23 
AnswerRe: Basic mp3/media player problem :( Pin
Giorgi Dalakishvili12-Oct-08 4:47
mentorGiorgi Dalakishvili12-Oct-08 4:47 
QuestionHiding control properties, Creating serializable control Pin
Andy Rama12-Oct-08 4:01
Andy Rama12-Oct-08 4:01 
AnswerRe: Hiding control properties, Creating serializable control Pin
DaveyM6912-Oct-08 6:25
professionalDaveyM6912-Oct-08 6:25 
QuestionRe: Hiding control properties, Creating serializable control Pin
Andy Rama28-Oct-08 22:41
Andy Rama28-Oct-08 22:41 
AnswerRe: Hiding control properties, Creating serializable control Pin
DaveyM6929-Oct-08 2:33
professionalDaveyM6929-Oct-08 2:33 
QuestionStgOpenStorageEx() Pin
Miss_hacker12-Oct-08 3:41
Miss_hacker12-Oct-08 3:41 
AnswerRe: StgOpenStorageEx() Pin
Dave Kreskowiak12-Oct-08 4:34
mveDave Kreskowiak12-Oct-08 4:34 
GeneralRe: StgOpenStorageEx() Pin
Miss_hacker12-Oct-08 6:27
Miss_hacker12-Oct-08 6:27 
GeneralRe: StgOpenStorageEx() Pin
Dave Kreskowiak12-Oct-08 7:35
mveDave Kreskowiak12-Oct-08 7:35 
GeneralRe: StgOpenStorageEx() Pin
Colin Angus Mackay12-Oct-08 12:08
Colin Angus Mackay12-Oct-08 12:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.