Click here to Skip to main content
15,902,854 members
Home / Discussions / C#
   

C#

 
GeneralRe: multi-threading in c# Pin
lord_laurent_r30-Jan-10 20:21
lord_laurent_r30-Jan-10 20:21 
GeneralRe: multi-threading in c# Pin
Luc Pattyn31-Jan-10 2:39
sitebuilderLuc Pattyn31-Jan-10 2:39 
GeneralRe: multi-threading in c# Pin
lord_laurent_r31-Jan-10 20:23
lord_laurent_r31-Jan-10 20:23 
GeneralRe: multi-threading in c# Pin
Luc Pattyn1-Feb-10 2:17
sitebuilderLuc Pattyn1-Feb-10 2:17 
GeneralRe: multi-threading in c# Pin
lord_laurent_r1-Feb-10 2:37
lord_laurent_r1-Feb-10 2:37 
GeneralRe: multi-threading in c# Pin
Luc Pattyn1-Feb-10 2:52
sitebuilderLuc Pattyn1-Feb-10 2:52 
GeneralRe: multi-threading in c# Pin
lord_laurent_r1-Feb-10 5:01
lord_laurent_r1-Feb-10 5:01 
QuestionControl derived from Listbox not drawing properly Pin
Russell Jones28-Jan-10 6:19
Russell Jones28-Jan-10 6:19 
I've got the following code running and the idea is that a row in the DB has a coloured letter in it to denote customer or supplier etc. The first row i highlight seems to vanish, the background for the row is blue and the selected index is set so that's all nice but the text disappears. If i click the row a second time the row unselects and the text comes back.

public partial class CompanyListControl : ListBox<br />
    {<br />
        int _previousIndex = 0;<br />
        public CompanyListControl()<br />
        {<br />
            InitializeComponent();<br />
            this.DrawMode = DrawMode.OwnerDrawFixed;<br />
        }<br />
        protected override void OnDrawItem(DrawItemEventArgs e)<br />
        {<br />
            base.OnDrawItem(e);<br />
            if (!DesignMode)<br />
            {<br />
                e.DrawBackground();<br />
                if (this.SelectedIndex == e.Index)<br />
                {<br />
                    if (_previousIndex != e.Index)<br />
                    {<br />
                        InvalidateItem(_previousIndex);<br />
                        DrawSelected(e);<br />
                        _previousIndex = e.Index;<br />
                    }<br />
                }<br />
                else<br />
                {<br />
                    DrawUnselected(e);<br />
                }<br />
            }<br />
        }<br />
        public void InvalidateItem(int index)<br />
        {<br />
            if ((index < 0) || (index >= this.Items.Count))<br />
                return;<br />
            object InvalidatedObject = this.Items[index];<br />
            this.Items.RemoveAt(index);<br />
            this.Items.Insert(index, InvalidatedObject);<br />
        }<br />
        private void DrawSelected(DrawItemEventArgs e)<br />
        {<br />
            if (e.Index == -1) return;<br />
            int RowWidth = e.Bounds.Width;<br />
            Font f = new Font("Arial Black", e.Font.Size);<br />
            Size s = TextRenderer.MeasureText("C", f);<br />
            int SalesPos = 0;<br />
            float PurchasePos = s.Width * 0.7f;<br />
            float TextPos = PurchasePos * 2;<br />
            int VerticalPos = e.Bounds.Top;<br />
            e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, Brushes.White, TextPos, e.Bounds.Top);<br />
            e.Graphics.DrawString("C", f, Brushes.Red, SalesPos, VerticalPos);<br />
<br />
        }<br />
        private void DrawUnselected(DrawItemEventArgs e)<br />
        {<br />
            int RowWidth = e.Bounds.Width;<br />
            Font f = new Font("Arial Black", e.Font.Size);<br />
            Size s = TextRenderer.MeasureText("C", f);<br />
            int SalesPos = 0;<br />
            float PurchasePos = s.Width * 0.8f;<br />
            float TextPos = PurchasePos * 2;<br />
            int VerticalPos = e.Bounds.Top;<br />
            e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, Brushes.Black, TextPos, e.Bounds.Top);<br />
            e.Graphics.DrawString("C", f, Brushes.Red, SalesPos, VerticalPos);<br />
        }<br />
        protected override void OnSelectedIndexChanged(EventArgs e)<br />
        {<br />
            base.OnSelectedIndexChanged(e);<br />
            this.Invalidate();<br />
        }<br />
    }


Does anyone have any ideas what might be wrong? I've added and removed all sorts of bits from the code and it doesn't seem to change the behaviour very much at all (to the point that I put some break points in just to check that this code was actually being run)

Thanks

Russ
AnswerRe: Control derived from Listbox not drawing properly Pin
Saksida Bojan28-Jan-10 7:54
Saksida Bojan28-Jan-10 7:54 
GeneralRe: Control derived from Listbox not drawing properly Pin
Russell Jones28-Jan-10 8:23
Russell Jones28-Jan-10 8:23 
GeneralRe: Control derived from Listbox not drawing properly Pin
Saksida Bojan28-Jan-10 8:28
Saksida Bojan28-Jan-10 8:28 
QuestionHow to handle Enter key... Pin
mukundkallapur28-Jan-10 5:33
mukundkallapur28-Jan-10 5:33 
AnswerRe: How to handle Enter key... Pin
OriginalGriff28-Jan-10 5:43
mveOriginalGriff28-Jan-10 5:43 
AnswerRe: How to handle Enter key... Pin
Alex Manolescu28-Jan-10 8:16
Alex Manolescu28-Jan-10 8:16 
QuestionGetting info from database in gridview Pin
Bizcrack28-Jan-10 4:03
Bizcrack28-Jan-10 4:03 
AnswerRe: Getting info from database in gridview Pin
loyal ginger28-Jan-10 4:14
loyal ginger28-Jan-10 4:14 
AnswerRe: Getting info from database in gridview Pin
kevinnicol28-Jan-10 4:42
kevinnicol28-Jan-10 4:42 
GeneralRe: Getting info from database in gridview Pin
OriginalGriff28-Jan-10 5:12
mveOriginalGriff28-Jan-10 5:12 
GeneralRe: Getting info from database in gridview Pin
dan!sh 28-Jan-10 5:48
professional dan!sh 28-Jan-10 5:48 
AnswerRe: Getting info from database in gridview Pin
dan!sh 28-Jan-10 5:46
professional dan!sh 28-Jan-10 5:46 
GeneralRe: Getting info from database in gridview Pin
Bizcrack28-Jan-10 8:51
Bizcrack28-Jan-10 8:51 
AnswerRe: Getting info from database in gridview Pin
Mycroft Holmes28-Jan-10 12:18
professionalMycroft Holmes28-Jan-10 12:18 
AnswerRe: Getting info from database in gridview Pin
yokzie29-Jan-10 20:13
yokzie29-Jan-10 20:13 
Questionaccess database and c# form-adding data Pin
johnnysmith128-Jan-10 2:15
johnnysmith128-Jan-10 2:15 
AnswerRe: access database and c# form-adding data Pin
EliottA28-Jan-10 2:44
EliottA28-Jan-10 2:44 

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.