This project is read-only.

GetControl<ListView> issues

Apr 21, 2008 at 2:53 AM
Im trying to get a ListView instance to be created, simply a 3.5 winforms project, with a list view on a form, using this wrapper

this code

ListView lview = wrapper.GetControl<ListView>("listView1");

lview is only ever null

in UI spy the automationId is listView1, but the name is not displayed, any ideas why null is all I get?

Cheers Rosco
Apr 21, 2008 at 6:14 AM
Can you send me the code which you are using?
Apr 21, 2008 at 6:58 AM
Edited Apr 23, 2008 at 8:15 AM
using System;
using Core;
using Core.Factory;
using Core.UIItems;
using Core.UIItems.WindowItems;
using NUnit.Framework;

namespace TestLib2005
public class UnitTest1
private readonly string _path = @"..\..\..\WhiteTest2005\bin\Debug\WhiteTest2005.exe";

protected Application application;
protected Window window;
private readonly string APP_TITLE = "Form1";
WhiteWrapper wrapper = null;

public void TestInitialize()
wrapper = new WhiteWrapper(path, APPTITLE);

public void Cleanup()


public void SelectRow()
Window win = wrapper.GetWindow(APP_TITLE);
ListView listView = win.Get<ListView>("listView1");
listView.Select("col1", "foo");
ListViewRows rows = listView.SelectedRows;
Assert.AreEqual(1, rows.Count);
Assert.AreEqual("foo", rows0.Cells0.Text);

class WhiteWrapper : IDisposable
private readonly Application _host = null;
private readonly Window _mainWindow = null;

/// <summary>
/// Initializes a new instance of the <see cref="WhiteWrapper"/> class.
/// </summary>
/// <param name="path">The path.</param>
public WhiteWrapper(string path)
_host = Application.Launch(path);

public WhiteWrapper(string path, string mainWindowTitle)
: this(path)
_mainWindow = GetWindow(mainWindowTitle);

public void Dispose()
if (_host != null)

public Window GetWindow(string title)
return _host.GetWindow(title, InitializeOption.NoCache);

public TControl GetControl<TControl>(string controlName) where TControl : UIItem
return _mainWindow.Get<TControl>(controlName);

P.S. I am using VS2008 RTM pro edition on XP sp2
Apr 23, 2008 at 8:01 AM
Edited Apr 23, 2008 at 10:43 AM
I have made a couple of observations using different setups for this scenario.

please note these observations are using Nunit 2.4.7 with a windows forms project and test class library both in .net 2

In a form with a single listview the load method for the form contains

listView1.View = View.Details;

in a test performing

Window win = wrapper.GetWindow(APP_TITLE);
ListView listView = win.Get<ListView>("listView1");
listView.Select("col1", "foo");

works in vs2008
but fails in 2005 with the error

Bricks.BricksException : Error invoking ListView.Select
----> Core.UIItems.UIActionException : Cannot get cell for col1

however using

Window win = wrapper.GetWindow(APP_TITLE);
ListView listView = win.Get<ListView>("listView1");
listView.Select("", "foo");

works in 2005
but fails in 2008 with the error

Bricks.BricksException : Error invoking ListView.Select
----> Core.Factory.UIItemSearchException : Cannot find column with text

my hunch is that maybe there is a problem with the method

public virtual ListViewRow Get(string column, string value)
return Find(delegate(ListViewRow obj)
return obj.Cellscolumn.Text.Equals(value);

in Core.UIItems.ListViewRows, here an empty string is being passed in as the column parameter. Could this cause some problems being empty, is there code to deal with an empty column that could have a bug?

Apr 23, 2008 at 11:06 AM
Edited Apr 28, 2008 at 12:35 AM
Doing some further testing in 2008, it seems the only way to get listView.Select("col1", "foo"); is to have the view configured in details view, any other view type results in

System.NullReferenceException : Object reference not set to an instance of an object.

So in summary trying to get the listview initialized
ListView listView = win.Get<ListView>("listView1");
listView will always be null for every view except the details view of the list view
Jun 8, 2008 at 4:34 PM
Sorry for not getting back on this for so long. I apologize for it. I have been relying on RSS feeds to keep track of the issue/discussions. I have raised an issue with codeplex, hopefully they would fix it.
Regarding your issue, I would get back to you soon.
Sorry again for this.
Jul 2, 2008 at 8:48 PM
I am unable to reproduce this problem. I tried what you mentioned. Do you have any handy sample for the application which has the listview?