Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Library question

2 views
Skip to first unread message

> Adrian <

unread,
Feb 9, 2007, 9:22:40 AM2/9/07
to
I am getting these errors:

DrawListViewItemEventArgs' could not be found
DrawListViewSubItemEventArgs' could not be found
DrawListViewColumnHeaderEventArgs' could not be found

I am already referencing both:
System.Drawing
System.Drawing.Design

Which else should I reference to get rid of these errors?

Adrian.


Jani Järvinen [MVP]

unread,
Feb 9, 2007, 9:43:44 AM2/9/07
to
Hello Adrian,

all the three classes are defined in System.Windows.Forms namespace, so add
"using System.Windows.Forms;" to your C# code.

That should do it!

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja...@removethis.dystopia.fi
http://www.saunalahti.fi/janij/


jpuopolo

unread,
Feb 9, 2007, 9:45:08 AM2/9/07
to
Adrian:

Maybe a silly question, but are you including a "using" directive?

jpuopolo

"> Adrian <" <n...@home.anywhere> wrote in message
news:45cc8391$0$717$5fc...@dreader2.news.tiscali.nl...

> Adrian <

unread,
Feb 9, 2007, 10:08:58 AM2/9/07
to
Not a silly question at all,
however "using" is there.
Adrian

--

P. de Ridder, drs econ., bsc psych.
Pearltree Software Development
www.pearltree.nl
www.pearltree.us
"jpuopolo" <jpuo...@hotmail.com> wrote in message
news:%23pA5ijF...@TK2MSFTNGP05.phx.gbl...

> Adrian <

unread,
Feb 9, 2007, 10:11:42 AM2/9/07
to
If have that reference in.
So that isn't the cause.
Adrian.

"Jani Järvinen [MVP]" <ja...@removethis.dystopia.fi> wrote in message
news:OGvAviFT...@TK2MSFTNGP03.phx.gbl...

Jani Järvinen [MVP]

unread,
Feb 9, 2007, 10:21:35 AM2/9/07
to
Hello,

can you post your code that shows the error and the complete error message?

There must be something else going on in your code if you have the
references/using statements already in place.

Willy Denoyette [MVP]

unread,
Feb 9, 2007, 1:06:34 PM2/9/07
to
"> Adrian <" <n...@home.anywhere> wrote in message
news:45cc8391$0$717$5fc...@dreader2.news.tiscali.nl...

Are you sure you are using Framework v2.0?

Willy.

> Adrian <

unread,
Feb 9, 2007, 1:25:52 PM2/9/07
to
The code was taken from MSDN

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.Windows.Forms;

namespace WindowsApplication1
{
public class Form1: Form
{
private ListView listView1 = new ListView();
private ContextMenu contextMenu1 = new ContextMenu();

public Form1()
{
// Initialize the ListView control.
listView1.BackColor = Color.Black;
listView1.ForeColor = Color.White;
listView1.Dock = DockStyle.Fill;
listView1.View = View.Details;
listView1.FullRowSelect = true;

// Add columns to the ListView control.
listView1.Columns.Add("Name", 72, HorizontalAlignment.Center);
listView1.Columns.Add("First", 72, HorizontalAlignment.Center);
listView1.Columns.Add("Second", 72, HorizontalAlignment.Center);
listView1.Columns.Add("Third", 72, HorizontalAlignment.Center);

// Create items and add them to the ListView control.
ListViewItem listViewItem1 = new ListViewItem(new string[] { "One", "20",
"30", "-40" }, -1);
ListViewItem listViewItem2 = new ListViewItem(new string[] { "Two",
"-250", "145", "37" }, -1);
ListViewItem listViewItem3 = new ListViewItem(new string[] { "Three",
"200", "800", "-1,001" }, -1);
ListViewItem listViewItem4 = new ListViewItem(new string[] { "Four", "not
available", "-2", "100" }, -1);
listView1.Items.AddRange(new ListViewItem[] { listViewItem1,
listViewItem2, listViewItem3, listViewItem4 });

// Initialize the shortcut menu and
// assign it to the ListView control.
contextMenu1.MenuItems.Add("List", new EventHandler(menuItemList_Click));
contextMenu1.MenuItems.Add("Details", new
EventHandler(menuItemDetails_Click));
listView1.ContextMenu = contextMenu1;

// Configure the ListView control for owner-draw and add
// handlers for the owner-draw events.
listView1.OwnerDraw = true;
listView1.DrawItem += new
DrawListViewItemEventHandler(listView1_DrawItem);
listView1.DrawSubItem += new
DrawListViewSubItemEventHandler(listView1_DrawSubItem);
listView1.DrawColumnHeader += new
DrawListViewColumnHeaderEventHandler(listView1_DrawColumnHeader);

// Add a handler for the MouseMove event to compensate for an
// extra DrawItem event that occurs the first time the mouse
// moves over each row.
listView1.MouseMove += new MouseEventHandler(listView1_MouseMove);

// Add a handler for the MouseUp event so an item can be
// selected by clicking anywhere along its width.
listView1.MouseUp += new MouseEventHandler(listView1_MouseUp);

// Initialize the form and add the ListView control to it.
this.ClientSize = new Size(292, 79);
this.FormBorderStyle = FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Text = "ListView OwnerDraw Example";
this.Controls.Add(listView1);
}

// Clean up any resources being used.
protected override void Dispose(bool disposing)
{
if (disposing)
{
contextMenu1.Dispose();
}
base.Dispose(disposing);
}

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new ListViewOwnerDraw());
}

// Sets the ListView control to the List view.
private void menuItemList_Click(object sender, EventArgs e)
{
listView1.View = View.List;
listView1.Invalidate();
}

// Sets the ListView control to the Details view.
private void menuItemDetails_Click(object sender, EventArgs e)
{
listView1.View = View.Details;

// Reset the tag on each item to re-enable the workaround in
// the MouseMove event handler.
foreach (ListViewItem item in listView1.Items)
{
item.Tag = null;
}
}

// Selects and focuses an item when it is clicked anywhere along
// its width. The click must normally be on the parent item text.
private void listView1_MouseUp(object sender, MouseEventArgs e)
{
ListViewItem clickedItem = listView1.GetItemAt(5, e.Y);
if (clickedItem != null)
{
clickedItem.Selected = true;
clickedItem.Focused = true;
}
}

// Draws the backgrounds for entire ListView items.
private void listView1_DrawItem(object sender, DrawListViewItemEventArgs
e)
{
if ((e.State & ListViewItemStates.Selected) != 0)
{
// Draw the background and focus rectangle for a selected item.
e.Graphics.FillRectangle(Brushes.Maroon, e.Bounds);
e.DrawFocusRectangle();
}
else
{
// Draw the background for an unselected item.
using (LinearGradientBrush brush =
new LinearGradientBrush(e.Bounds, Color.Orange,
Color.Maroon, LinearGradientMode.Horizontal))
{
e.Graphics.FillRectangle(brush, e.Bounds);
}
}

// Draw the item text for views other than the Details view.
if (listView1.View != View.Details)
{
e.DrawText();
}
}

// Draws subitem text and applies content-based formatting.
private void listView1_DrawSubItem(object sender,
DrawListViewSubItemEventArgs e)
{
TextFormatFlags flags = TextFormatFlags.Left;

using (StringFormat sf = new StringFormat())
{
// Store the column text alignment, letting it default
// to Left if it has not been set to Center or Right.
switch (e.Header.TextAlign)
{
case HorizontalAlignment.Center:
sf.Alignment = StringAlignment.Center;
flags = TextFormatFlags.HorizontalCenter;
break;
case HorizontalAlignment.Right:
sf.Alignment = StringAlignment.Far;
flags = TextFormatFlags.Right;
break;
}

// Draw the text and background for a subitem with a
// negative value.
double subItemValue;
if (e.ColumnIndex > 0 && Double.TryParse(
e.SubItem.Text, NumberStyles.Currency,
NumberFormatInfo.CurrentInfo, out subItemValue) &&
subItemValue < 0)
{
// Unless the item is selected, draw the standard
// background to make it stand out from the gradient.
if ((e.ItemState & ListViewItemStates.Selected) == 0)
{
e.DrawBackground();
}

// Draw the subitem text in red to highlight it.
e.Graphics.DrawString(e.SubItem.Text,
listView1.Font, Brushes.Red, e.Bounds, sf);

return;
}

// Draw normal text for a subitem with a nonnegative
// or nonnumerical value.
e.DrawText(flags);
}
}

// Draws column headers.
private void listView1_DrawColumnHeader(object sender,
DrawListViewColumnHeaderEventArgs e)
{
using (StringFormat sf = new StringFormat())
{
// Store the column text alignment, letting it default
// to Left if it has not been set to Center or Right.
switch (e.Header.TextAlign)
{
case HorizontalAlignment.Center:
sf.Alignment = StringAlignment.Center;
break;
case HorizontalAlignment.Right:
sf.Alignment = StringAlignment.Far;
break;
}

// Draw the standard header background.
e.DrawBackground();

// Draw the header text.
using (Font headerFont =
new Font("Helvetica", 10, FontStyle.Bold))
{
e.Graphics.DrawString(e.Header.Text, headerFont,
Brushes.Black, e.Bounds, sf);
}
}
return;
}

// Forces each row to repaint itself the first time the mouse moves over
// it, compensating for an extra DrawItem event sent by the wrapped
// Win32 control.
private void listView1_MouseMove(object sender, MouseEventArgs e)
{
ListViewItem item = listView1.GetItemAt(e.X, e.Y);
if (item != null && item.Tag == null)
{
listView1.Invalidate(item.Bounds);
item.Tag = "tagged";


}
}
}
}
"Jani Järvinen [MVP]" <ja...@removethis.dystopia.fi> wrote in message

news:euOz43FT...@TK2MSFTNGP03.phx.gbl...

> Adrian <

unread,
Feb 9, 2007, 3:15:07 PM2/9/07
to
Yes I have it on board
Adrian

"Willy Denoyette [MVP]" <willy.d...@telenet.be> wrote in message
news:OdLjKUHT...@TK2MSFTNGP03.phx.gbl...

> Adrian <

unread,
Feb 10, 2007, 7:52:17 AM2/10/07
to
I have got it to run. It would not run on VS2003, but it will run on V2005.
I did make some changes though. However the header back color is read only,
so I am stuck, because specifically that I wanted to change.

Adrian


"> Adrian <" <n...@home.anywhere> wrote in message

news:45ccd62e$0$727$5fc...@dreader2.news.tiscali.nl...

Willy Denoyette [MVP]

unread,
Feb 10, 2007, 10:08:23 AM2/10/07
to
"> Adrian <" <n...@home.anywhere> wrote in message
news:45cdbfe4$0$711$5fc...@dreader2.news.tiscali.nl...

>I have got it to run. It would not run on VS2003, but it will run on V2005.
> I did make some changes though. However the header back color is read only,
> so I am stuck, because specifically that I wanted to change.
>
>

So you were not running V2 of the framework after all, VS2003 targets V1.x!

Willy.

0 new messages