Click here to Skip to main content
15,900,818 members
Home / Discussions / C#
   

C#

 
GeneralRe: XML Deserialization Pin
Estys11-Jan-11 22:47
Estys11-Jan-11 22:47 
Questionglobal vars names Pin
sadas232341s10-Jan-11 23:06
sadas232341s10-Jan-11 23:06 
AnswerRe: global vars names Pin
Pete O'Hanlon10-Jan-11 23:09
mvePete O'Hanlon10-Jan-11 23:09 
AnswerRe: global vars names Pin
OriginalGriff10-Jan-11 23:29
mveOriginalGriff10-Jan-11 23:29 
AnswerRe: global vars names Pin
Luc Pattyn11-Jan-11 2:05
sitebuilderLuc Pattyn11-Jan-11 2:05 
AnswerRe: global vars names Pin
PIEBALDconsult11-Jan-11 2:16
mvePIEBALDconsult11-Jan-11 2:16 
AnswerRe: global vars names Pin
RaviRanjanKr12-Jan-11 4:25
professionalRaviRanjanKr12-Jan-11 4:25 
QuestionListBox control - Freezing one or more rows at top? Pin
AussieLew10-Jan-11 15:44
AussieLew10-Jan-11 15:44 
I have a Windows Forms ListBox object showing items that originate in a dictionary.
To apply different coloring etc to some of the entries I have set
dropDownListBox.DrawMode = DrawMode.OwnerDrawFixed
and handling the listbox DrawItem and MeasureItem events.

The different colored items are basically additional choices or items I add or remove depending on other factors.
These are commands if you like eg. "Advanced Filter", "Remove This Filter" etc and always appear at the top of the listbox items, and are highlighted to separate them from the normal data values.
When I show the listbox I set the dropDownListBox.SelectedItem to the previously selected item which may be well down the list.

I would like to be able to "freeze" the required top row(s) or commands eg "Advanced Filter", so that as I scroll down, or the listbox shows with the previously selected item, the required rows are always visible.

This would save scrolling back right back to the start to select "Advanced Filter".

Not having much joy so far, can anyone assist?

Thanks
AussieLew

DrawItem and MeasureItem handlers below...


        void dropDownListBox_DrawItem(object sender, DrawItemEventArgs e)
            {
            Brush myBrush = Brushes.Green;
            Brush backBrush = Brushes.Red; // This color not used
           
            // string to draw
            string listString = dropDownListBox.Items[e.Index].ToString();

            // paint the list background
            e.DrawBackground();

            switch (listString)
                {
                case "Advanced Filter...":
                    myBrush = Brushes.DarkGreen;
                    backBrush = Brushes.PaleGreen;
                    e.Graphics.FillRectangle(backBrush, e.Bounds);
                    // check what filter commands are included in the list
                    // draw a separator line below the command if it is the last before the autofilter choices
                    if (filterCommandFlag == 2)
                        {
                        // needed to draw the line at e.Bounds.Bottom-1 otherwise the line was overwritten at times
                        e.Graphics.DrawLine(Pens.Green, e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1);
                        }
                    break;

                case "Remove This Filter":
                    myBrush = Brushes.DarkGreen;
                    backBrush = Brushes.PaleGreen;
                    e.Graphics.FillRectangle(backBrush, e.Bounds);
                    // no need for separator line here. This entry is never the last.
                    //e.Graphics.DrawLine(Pens.Black, e.Bounds.Left, e.Bounds.Bottom-1, e.Bounds.Right, e.Bounds.Bottom-1);
                    break;

                case "Remove All Filters":
                    myBrush = Brushes.OrangeRed;
                    backBrush = Brushes.PaleGreen;
                    e.Graphics.FillRectangle(backBrush, e.Bounds);
                    // check what filter commands are included in the list
                    // draw a separator line below the command if it is the last before the autofilter choices
                    if (filterCommandFlag > 3 && filterCommandFlag < 8)
                        {
                        // needed to draw the line at e.Bounds.Bottom-1 otherwise the line was overwritten at times
                        e.Graphics.DrawLine(Pens.Green, e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1);
                        }
                    break;

                case "Blanks":
                    myBrush = Brushes.OrangeRed;
                    backBrush = Brushes.PaleGreen;
                    e.Graphics.FillRectangle(backBrush, e.Bounds);
                    // check what filter commands are included in the list
                    // draw a separator line below the command if it is the last before the autofilter choices
                    //if (filterCommandFlag == 3)
                    //    {
                    //    // needed to draw the line at e.Bounds.Bottom-1 otherwise the line was overwritten at times
                    //    e.Graphics.DrawLine(Pens.Green, e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1);
                    //    }

                    break;

                case "NonBlanks":
                    myBrush = Brushes.OrangeRed;
                    backBrush = Brushes.PaleGreen;
                    e.Graphics.FillRectangle(backBrush, e.Bounds);
                    // check what filter commands are included in the list
                    // draw a separator line below the command if it is the last before the autofilter choices
                    if (filterCommandFlag > 7)
                        {
                        // needed to draw the line at e.Bounds.Bottom-1 otherwise the line was overwritten at times
                        e.Graphics.DrawLine(Pens.Green, e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1);
                        }

                    break;
                }
            // If the item is the selected item, then draw the rectangle
            // filled in. The item is selected when a bitwise And  
            // of the State property and the DrawItemState.Selected 
            // property is true.
            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                {
                e.Graphics.FillRectangle(Brushes.SpringGreen, e.Bounds);
                // Draw a rectangle in blue around the selected item.
                //e.Graphics.DrawRectangle(Pens.Blue, e.Bounds);
                }
            // draw the string
            e.Graphics.DrawString(listString, e.Font, myBrush, e.Bounds, StringFormat.GenericDefault);
            }



private void dropDownListBox_MeasureItem(object sender, MeasureItemEventArgs e)
            {
            Font font = dropDownListBox.Font;
            SizeF stringSize = e.Graphics.MeasureString(font.Name, font);
            e.ItemHeight = (int)stringSize.Height;

            }

AnswerRe: ListBox control - Freezing one or more rows at top? Pin
Luc Pattyn10-Jan-11 17:56
sitebuilderLuc Pattyn10-Jan-11 17:56 
QuestionYearly Calendar Pin
Ali Al Omairi(Abu AlHassan)10-Jan-11 8:40
professionalAli Al Omairi(Abu AlHassan)10-Jan-11 8:40 
AnswerRe: Yearly Calendar Pin
Dalek Dave10-Jan-11 8:56
professionalDalek Dave10-Jan-11 8:56 
GeneralRe: Yearly Calendar Pin
Ali Al Omairi(Abu AlHassan)10-Jan-11 9:13
professionalAli Al Omairi(Abu AlHassan)10-Jan-11 9:13 
GeneralRe: Yearly Calendar Pin
Dalek Dave10-Jan-11 9:42
professionalDalek Dave10-Jan-11 9:42 
GeneralRe: Yearly Calendar Pin
Ali Al Omairi(Abu AlHassan)10-Jan-11 9:48
professionalAli Al Omairi(Abu AlHassan)10-Jan-11 9:48 
AnswerRe: Yearly Calendar Pin
Henry Minute10-Jan-11 11:17
Henry Minute10-Jan-11 11:17 
GeneralRe: Yearly Calendar Pin
Ali Al Omairi(Abu AlHassan)10-Jan-11 11:30
professionalAli Al Omairi(Abu AlHassan)10-Jan-11 11:30 
GeneralRe: Yearly Calendar Pin
Henry Minute10-Jan-11 12:05
Henry Minute10-Jan-11 12:05 
GeneralRe: Yearly Calendar Pin
Ali Al Omairi(Abu AlHassan)10-Jan-11 13:25
professionalAli Al Omairi(Abu AlHassan)10-Jan-11 13:25 
GeneralRe: Yearly Calendar Pin
Henry Minute10-Jan-11 13:45
Henry Minute10-Jan-11 13:45 
GeneralRe: Yearly Calendar Pin
Ali Al Omairi(Abu AlHassan)10-Jan-11 14:01
professionalAli Al Omairi(Abu AlHassan)10-Jan-11 14:01 
QuestionMysql in vb.net2008 on vista then its give error(Unable to connect to any of the specified MySQL hosts.) Pin
Piyush Vardhan Singh9-Jan-11 20:08
Piyush Vardhan Singh9-Jan-11 20:08 
AnswerRe: Mysql in vb.net2008 on vista then its give error(Unable to connect to any of the specified MySQL hosts.) Pin
Luc Pattyn10-Jan-11 0:50
sitebuilderLuc Pattyn10-Jan-11 0:50 
GeneralRe: Mysql in vb.net2008 on vista then its give error(Unable to connect to any of the specified MySQL hosts.) Pin
DaveyM6910-Jan-11 3:04
professionalDaveyM6910-Jan-11 3:04 
AnswerRe: Mysql in vb.net2008 on vista then its give error(Unable to connect to any of the specified MySQL hosts.) Pin
Bernhard Hiller10-Jan-11 4:34
Bernhard Hiller10-Jan-11 4:34 
AnswerRe: Mysql in vb.net2008 on vista then its give error(Unable to connect to any of the specified MySQL hosts.) Pin
phil.o10-Jan-11 5:16
professionalphil.o10-Jan-11 5:16 

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.