Hallo,
Linda Liu said:
Hi Dieter,
Thank you for your reply!
The problem you entered has been reproduced, but our evaluation determined
that it does not meet the criteria to be addressed in this release. This
evaluation is carefully done and considers many aspects including fix
cost,
breaking changes, globalization, performance, etc.
But this meens a WinForm App with an TreeView with Checkboxes is not usable
under Vista.
I think checkboxes will normally be used to select functions that will run
on the nodes.
In our app the checkbox will delete and change main configuration entries in
a database.
When an node is visibly not check but the state in Framework says it ist
checked the functions will run.
This makes TreeView with Checkboxes in every WinForm application not usable.
This brings me to another question:
Does this means error in the .Net Framework will not be fixed because of the
costs?
The error will not affect breaking changes and globalization aspects.
Performance could be affected because an TreeViewItem State must be asked
when a mouse button is pressed.
Additionally, as part of planning and analysis of future versions this bug
will be considered again for possible inclusion.
dialog inside a library that is used from an C++/CLI application.
How about the other solution of drawing the TreeView by ourselves that I
provided in my first reply?
ImageLists are not attended and the look is not the same as in Vista.
What must be change to get the same look as in Vista?
What about Visual Styles?
What about the property HideSelection?
I could send you an image from a test app and an test Project.
I adopted your code in a new class TreeViewVista inherited from TreeView.
On the left side I used the new class TreeViewVista.
On the right side I used the original class TreeView.
Under every control there are labels. They will be filled with the state of
the first related TreeNode.
Here is the Code of my TreeViewVista class:
Where will I get the original bitmaps for plus and minus?
What must be added to get the same look as the original TreeView?
File: TreeViewErrorVista.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace TreeViewErrorVista
{
public class TreeViewVista : TreeView
{
public TreeViewVista()
{
if (Environment.OSVersion.Version.Major >= 6)
{
DrawMode = TreeViewDrawMode.OwnerDrawAll;
DrawNode += new DrawTreeNodeEventHandler(treeView1_DrawNode);
}
}
private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
int left = e.Bounds.X;
int top = e.Bounds.Y;
int height = e.Bounds.Height;
int nodeleft = e.Node.Bounds.X;
int nodetop = e.Node.Bounds.Y;
int nodeheight = e.Node.Bounds.Height;
int nodewidth = e.Node.Bounds.Width;
int linelength =10;
int checkboxwidth = 13;
int checknodespace = 2;
using (Pen p = new Pen(Color.Gray))
{
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
int lineleft = nodeleft-checknodespace-checkboxwidth-linelength;
//draw horizontal dot line
e.Graphics.DrawLine(p, lineleft, top + height / 2, lineleft +
linelength, top + height / 2);
// draw the up half vertical dot line
if (e.Node.PrevNode != null || e.Node.Parent != null)
{
e.Graphics.DrawLine(p, lineleft, top, lineleft, top + height / 2);
}
// draw the down half vertical dot line
if (e.Node.NextNode != null)
{
e.Graphics.DrawLine(p, lineleft, top + height / 2,
lineleft, e.Node.NextNode.Bounds.Top);
}
// draw plus/minus image
if (e.Node.Nodes.Count > 0)
{
if (!e.Node.IsExpanded)
{
e.Graphics.DrawImage(Properties.Resources.plus,
lineleft - Properties.Resources.plus.Width / 2, top +
(height -
Properties.Resources.plus.Height) / 2);
}
else
{
e.Graphics.DrawImage(Properties.Resources.minus,
lineleft - Properties.Resources.minus.Width / 2, top +
(height -
Properties.Resources.minus.Height) / 2);
}
}
// draw the vertical dot line for the parent nodes if necessary
TreeNode parentNode = e.Node.Parent;
int parentNodeLeftDistance = checknodespace + checkboxwidth +
linelength;
while (parentNode != null)
{
if (parentNode.NextNode != null)
{
e.Graphics.DrawLine(p, parentNode.Bounds.X -
parentNodeLeftDistance,
top, parentNode.Bounds.X - parentNodeLeftDistance, top +
height);
}
parentNode = parentNode.Parent;
}
}
// draw checkbox
if (e.Node.Checked)
{
ControlPaint.DrawCheckBox(e.Graphics, new Rectangle(nodeleft -
checkboxwidth - checknodespace,
top + (height - checkboxwidth) / 2, checkboxwidth, checkboxwidth),
ButtonState.Checked);
}
else
{
ControlPaint.DrawCheckBox(e.Graphics, new Rectangle(nodeleft -
checkboxwidth - checknodespace, top + (height - checkboxwidth) / 2,
checkboxwidth, checkboxwidth), ButtonState.Normal);
}
// erase the previous node text
using (Brush b = new SolidBrush(BackColor))
{
e.Graphics.DrawString(e.Node.Text,Font, b, nodeleft, nodetop);
}
// draw node text and highlight rectangle
if (e.Node.IsSelected)
{
ControlPaint.DrawFocusRectangle(e.Graphics, e.Node.Bounds);
e.Graphics.FillRectangle(Brushes.LightSkyBlue, new
Rectangle(nodeleft + 1, nodetop + 1, nodewidth - 2, nodeheight - 2));
using (Brush b = new SolidBrush(Color.White))
{
e.Graphics.DrawString(e.Node.Text, Font, b, nodeleft, nodetop);
}
}
else
{
using (Brush b = new SolidBrush(ForeColor))
{
e.Graphics.DrawString(e.Node.Text, Font, b, nodeleft, nodetop);
}
}
}
}
}
File: form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TreeViewErrorVista
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (treeViewVista1.Nodes[0].Checked)
{
lbtreeViewVista1.Text = "Checked";
}
else
{
lbtreeViewVista1.Text = "Not checked";
}
if (treeView1.Nodes[0].Checked)
{
lbtreeView1.Text = "Checked";
}
else
{
lbtreeView1.Text = "Not checked";
}
if (treeViewVista2.Nodes[0].Checked)
{
lbtreeViewVista2.Text = "Checked";
}
else
{
lbtreeViewVista2.Text = "Not checked";
}
if (treeView2.Nodes[0].Checked)
{
lbtreeView2.Text = "Checked";
}
else
{
lbtreeView2.Text = "Not checked";
}
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (TreeView tv in new TreeView[] { treeView1, treeView2,
treeViewVista1, treeViewVista2 })
{
TreeNode myNode = new TreeNode("TestNode", 0, 0);
tv.Nodes.Add(myNode);
myNode.Nodes.Add("SubNode2");
myNode.Nodes.Add("SubNode3");
tv.Nodes.Add(new TreeNode("TestNode2", 0, 0));
tv.Nodes.Add(new TreeNode("TestNode3", 0, 0));
}
}
}
}
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
Sincerely.
Dieter Pelz