Hi, I am writing the unit test for our application. It use "listview
component" in some functions. The following code work fine and get c =
1 in Windows Application mode, but fail in unit test which get c = 0 :
listView2.Items.Add("xxx");
listView2.Items[0].Selected = true;
int c = listView2.SelectedItems.Count;
in unit test, we create listView2 by this way:
class CreateListViews
{
private ListView listview1;
private System.Windows.Forms.ColumnHeader Number;
private System.Windows.Forms.ColumnHeader Start;
private System.Windows.Forms.ColumnHeader End;
private System.Windows.Forms.ColumnHeader Event;
private System.Windows.Forms.ColumnHeader Length;
public ListView GetListViews()
{
listview1 = new System.Windows.Forms.ListView();
this.Number = new System.Windows.Forms.ColumnHeader();
this.Start = new System.Windows.Forms.ColumnHeader();
this.End = new System.Windows.Forms.ColumnHeader();
this.Event = new System.Windows.Forms.ColumnHeader();
this.Length = new System.Windows.Forms.ColumnHeader();
listview1.Columns.AddRange(new
System.Windows.Forms.ColumnHeader[] {
this.Number,
this.Start,
this.End,
this.Event,
this.Length});
return listview1;
}
}
do someone know why, and what wrong? 2 2180
Hi Justdo,
I also faced a similar problem before. I think it has some sort of a bug. If
you add the control to a parent - if windows forms, then it will work. (eg.
Controls.Add(listView2);). As an alternate, in console application you can
use
Rectangle rect = listView2.Items[0].Bounds;
before getting the count.
HTH
Cheers,
Chester
"ju****@alumni.ice.ntnu.edu.tw" wrote:
Hi, I am writing the unit test for our application. It use "listview
component" in some functions. The following code work fine and get c =
1 in Windows Application mode, but fail in unit test which get c = 0 :
listView2.Items.Add("xxx");
listView2.Items[0].Selected = true;
int c = listView2.SelectedItems.Count;
in unit test, we create listView2 by this way:
class CreateListViews
{
private ListView listview1;
private System.Windows.Forms.ColumnHeader Number;
private System.Windows.Forms.ColumnHeader Start;
private System.Windows.Forms.ColumnHeader End;
private System.Windows.Forms.ColumnHeader Event;
private System.Windows.Forms.ColumnHeader Length;
public ListView GetListViews()
{
listview1 = new System.Windows.Forms.ListView();
this.Number = new System.Windows.Forms.ColumnHeader();
this.Start = new System.Windows.Forms.ColumnHeader();
this.End = new System.Windows.Forms.ColumnHeader();
this.Event = new System.Windows.Forms.ColumnHeader();
this.Length = new System.Windows.Forms.ColumnHeader();
listview1.Columns.AddRange(new
System.Windows.Forms.ColumnHeader[] {
this.Number,
this.Start,
this.End,
this.Event,
this.Length});
return listview1;
}
}
do someone know why, and what wrong?
Hi Chester,
thx for your response, the second method is in effect, but the method
using windows forms is fail, the code as following:
class CreateListViews
{
//added
static Form manageForm = new Form();
private ListView listview1;
private System.Windows.Forms.ColumnHeader Number;
private System.Windows.Forms.ColumnHeader Start;
private System.Windows.Forms.ColumnHeader End;
private System.Windows.Forms.ColumnHeader Event;
private System.Windows.Forms.ColumnHeader Length;
public ListView GetListViews()
{
listview1 = new System.Windows.Forms.ListView();
this.Number = new System.Windows.Forms.ColumnHeader();
this.Start = new System.Windows.Forms.ColumnHeader();
this.End = new System.Windows.Forms.ColumnHeader();
this.Event = new System.Windows.Forms.ColumnHeader();
this.Length = new System.Windows.Forms.ColumnHeader();
listview1.Columns.AddRange(new
System.Windows.Forms.ColumnHeader[] {
this.Number,
this.Start,
this.End,
this.Event,
this.Length});
this.listview1.FullRowSelect = true;
this.listview1.GridLines = true;
this.listview1.LabelEdit = true;
listview1.TabIndex = 0;
//added
manageForm.Controls.Add(listview1);
return listview1;
}
}
Is anything I did wrong? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Lian Liming |
last post by:
Hi, all
I want to write my own error handler function in php by using
"set_error_handler()" function. I have made a test for this function but
found it did not work. My test code is as following:...
|
by: gvutcc |
last post by:
// for ANSI/UNICODE
#ifdef UNICODE
#define $ L
#else
#define $
#endif /* UNICODE */
|
by: timon |
last post by:
I had created a project in .net 2003. However I can;t work on the previous
version of .net. Is there have any way I can make the it work on previous
version of .net?
|
by: ice godwater via .NET 247 |
last post by:
(Type your message here)
I created a Web Service with SSL ,my remote WinForm can work well with it ,but the remote WebFrom can't work.
--------------------------------
From: ice godwater
...
|
by: Edward Diener |
last post by:
By reuse, I mean a function in an assembly which is called in another
assembly.
By a mixed-mode function I mean a function whose signature has one or
more CLR types and one or more non-CLR...
|
by: Allen Maki |
last post by:
Hi everybody,
I need your help.
I am using Visual C++ .NET
How can I make Console::ReadLine accepts int? In other words.
I know I can do this:
|
by: MC |
last post by:
I had 2 folders I couldn't move or delete. Each had contained the
executable from a console-mode Visual Studio 2008 C# application. On trying
to move the folders I got the entirely misleading UAC...
|
by: Siegfried Heintze |
last post by:
Can someone point me to an example of a little program that emits non-ascii
Unicode characters (Russian or Chinese perhaps)? The unicode
Russian/Cyrillic alphabet starts at 0x410. Is this possible...
|
by: =?Utf-8?B?U2llZ2ZyaWVkIEhlaW50emU=?= |
last post by:
The following perl program prints the russian alphabet in Cryllic when I use
the urxvt console from cygwin. It seems to understand UTF-8 better than
cmd.exe.
perl -wle "binmode STDOUT, q; print...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |