GIDForums  

Go Back   GIDForums > Computer Programming Forums > .NET Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-Mar-2008, 12:04
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 440
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

CreateParams does not exist in namespace


I'm trying to create a virtual list control in C# like the example here, but I keep getting this build error:
Code:
The type or namespace name 'CreateParams' does not exist in the namespace 'System.Windows.Forms' (are you missing an assembly reference?)

Here is the code:
C-SHARP / C# Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;





namespace PocketPCTest
{   
    public partial class VirtualListBox : ListBox
    {
        /*
        * Listbox Styles
        */
        private const int LBS_NOTIFY = 0x0001;
        private const int LBS_SORT = 0x0002;
        private const int LBS_NOREDRAW = 0x0004;
        private const int LBS_MULTIPLESEL = 0x0008;
        private const int LBS_OWNERDRAWFIXED = 0x0010;
        private const int LBS_OWNERDRAWVARIABLE = 0x0020;
        private const int LBS_HASSTRINGS = 0x0040;
        private const int LBS_USETABSTOPS = 0x0080;
        private const int LBS_NOINTEGRALHEIGHT = 0x0100;
        private const int LBS_MULTICOLUMN = 0x0200;
        private const int LBS_WANTKEYBOARDINPUT = 0x0400;
        private const int LBS_EXTENDEDSEL = 0x0800;
        private const int LBS_DISABLENOSCROLL = 0x1000;
        private const int LBS_NODATA = 0x2000;
        private const int LB_GETCOUNT = 0x018B;
        private const int LB_SETCOUNT = 0x01A7;
        
        public VirtualListBox()
        {
            InitializeComponent();
        }
    

        /// <summary>
        /// Sets up the <see cref="CreateParams" /> object to tell 
        /// Windows how the ListBox control should be created.  In 
        /// this instance the default configuration is modified to 
        /// remove <c>LBS_HASSTRINGS</c> and <c>LBS_SORT</c> 
        /// styles and to add <c>LBS_NODATA</c>and LBS_OWNERDRAWFIXED 
        /// styles. This converts the ListBox into a Virtual ListBox.
        /// </summary>
        protected override System.Windows.Forms.CreateParams CreateParams
        {
        get
        {
            CreateParams defParams = base.CreateParams;
            defParams.Style = defParams.Style & ~LBS_HASSTRINGS;
            defParams.Style = defParams.Style & ~LBS_SORT;
            defParams.Style = defParams.Style | 
                LBS_OWNERDRAWFIXED | LBS_NODATA;
            return defParams;
        }
        }
    
        [DllImport("user32", CharSet = CharSet.Auto)]
        private extern static int SendMessage(
        IntPtr hWnd, int msg, int wParam, IntPtr lParam);
    
        /// <summary>
        /// Gets or sets the number of virtual items in the ListBox.
        /// </summary>
        public int Count
        {
        get
        {
            return SendMessage(this.Handle, 
                LB_GETCOUNT, 0, IntPtr.Zero);
        }
        set
        {
            SendMessage(this.Handle, 
                 LB_SETCOUNT, value, IntPtr.Zero);
        }    
        }
    
        /// <summary>
        /// Throws an exception.  All the items for a Virtual ListBox 
        /// are externally managed.
        /// </summary>
        /// <remarks>The selected index can be obtained using 
        /// the <see cref="SelectedIndex"/> and
        /// <see cref="SelectedIndices"/> properties.
        /// </remarks>
        [BrowsableAttribute(false)]
        public new SelectedObjectCollection SelectedItems
        {
            get
            {
                throw new InvalidOperationException("A Virtual ListBox does not have a SelectedObject collection");
            }
        }
    
        /// <summary>
        /// Gets/sets the selected index in the control.  If the 
        /// control has the multi-select style, then the first 
        /// selected item is returned.
        /// </summary>
        public new int SelectedIndex
        {
            get
            {
            int selIndex = -1;
            if (SelectionMode == SelectionMode.One)
            {
                selIndex = SendMessage(this.Handle, 
                    LB_GETCURSEL, 0, IntPtr.Zero);
            }         
            else if ((SelectionMode == SelectionMode.MultiExtended) || 
                (SelectionMode == SelectionMode.MultiSimple))
            {
                int selCount = SendMessage(this.Handle, 
                    LB_GETSELCOUNT, 0, IntPtr.Zero);
                if (selCount > 0)
                {
                    IntPtr buf = Marshal.AllocCoTaskMem(4);
                    SendMessage(this.Handle, LB_GETSELITEMS, 1, buf);
                    selIndex = Marshal.ReadInt32(buf);
                    Marshal.FreeCoTaskMem(buf);
                }
            }
            return selIndex;
            }
            set
            {
            if (SelectionMode == SelectionMode.One)
            {
                SendMessage(this.Handle, 
                    LB_SETCURSEL, value, IntPtr.Zero);
            }
            else if ((SelectionMode == SelectionMode.MultiExtended) || 
                (SelectionMode == SelectionMode.MultiSimple))
            {
                // clear any existing selection:
                SendMessage(this.Handle, LB_SETSEL, 0, new IntPtr(-1));
                // set the requested selection
                SendMessage(this.Handle, LB_SETSEL, 1, (IntPtr) value);
            }
        }   
    }      
  }
}

NOTE: This is for a PocketPC app...maybe that is the problem????

Does anyone have any ideas?
 
 

Recent GIDBlogToyota - 2008 July Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Major newbie problem cynack MS Visual C++ / MFC Forum 1 08-Apr-2007 11:25
CD/DVD does not read/or exist bdove Computer Hardware Forum 3 14-Apr-2006 11:21
Where is namespace std Defined? BobbyMurcerFan CPP / C++ Forum 5 13-Oct-2004 14:27
Which Header Files to Use?? BobbyMurcerFan CPP / C++ Forum 8 16-Jun-2004 18:29
ClassView not showing my classes (VC++, namespace, headers) ?!?!? djovanov CPP / C++ Forum 1 13-Jan-2004 04:54

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 04:40.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.