By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,276 Members | 1,452 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,276 IT Pros & Developers. It's quick & easy.

How to fill listview in a different class and file?

P: n/a
In Form1.cs I have defined the "InstituteAdministrator"
class which contains ListView "listViewAddress". In a second
file (FormTreeView.cs) I have the class FormTreeView with
the method "dataTreeView1_AfterSelect". When the user
selects a node in the treeview, then listViewAddress should
be filled and displayed with the corresponding addresses.

As long as I keep the whole thing in one file, it works
fine, but not with two files and two classes.

I want to use dotnetmagic.com's libraries, which come with
this two-files example for docking.

First I created a method within the InstituteAdministrator
class which establishes the database connection and fills
the listview. Within FormTreeView class I made a reference
to the Institute Administrator class and called the filling
method I defined, passing "e.Node.Tag.ToString()" as
parameter to the method.

The program seemed to work, however the data is not
displaying in the listview. Since then I'm trying out (try
and error...). So far I did not find sufficient information
in books or online examples to help me to understand what is
going on. (needless to say that I'm a newbie)

Which are the steps to make this work? Any hints, anyone?

Link to screenshots and source-files:
http://www.osswald.com/vstudio/

Direct link to source files (flash-paper prints):
http://www.osswald.com/vstudio/images/form1.cs.swf
http://www.osswald.com/vstudio/image...reeView.cs.swf

Thanks, Oliver

Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
hi

I assume you have both forms visible, if so you need to pass a reference of
the listviewform to the FormTreeView, you can do that whne you create the
latter. in the first form create a public method that will receive the ID
from thre selected tree, then the method will retrieve the data and populate
the listview

In the worst case that the TreeView's form is not create by the first form
you could keep a reference to the currently displayed form in a static
property.
hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"Ole Baba" <ol****@gmx.net> wrote in message
news:db**********@news.hispeed.ch...
In Form1.cs I have defined the "InstituteAdministrator" class which
contains ListView "listViewAddress". In a second file (FormTreeView.cs) I
have the class FormTreeView with the method "dataTreeView1_AfterSelect".
When the user selects a node in the treeview, then listViewAddress should
be filled and displayed with the corresponding addresses.

As long as I keep the whole thing in one file, it works fine, but not with
two files and two classes.

I want to use dotnetmagic.com's libraries, which come with this two-files
example for docking.

First I created a method within the InstituteAdministrator class which
establishes the database connection and fills the listview. Within
FormTreeView class I made a reference to the Institute Administrator class
and called the filling method I defined, passing "e.Node.Tag.ToString()"
as parameter to the method.

The program seemed to work, however the data is not displaying in the
listview. Since then I'm trying out (try and error...). So far I did not
find sufficient information in books or online examples to help me to
understand what is going on. (needless to say that I'm a newbie)

Which are the steps to make this work? Any hints, anyone?

Link to screenshots and source-files:
http://www.osswald.com/vstudio/

Direct link to source files (flash-paper prints):
http://www.osswald.com/vstudio/images/form1.cs.swf
http://www.osswald.com/vstudio/image...reeView.cs.swf

Thanks, Oliver

Nov 17 '05 #2

P: n/a
"Ignacio Machin \( .NET/ C# MVP \)" wrote:
I assume you have both forms visible,
if so you need to pass a reference of
the listviewform to the FormTreeView,
you can do that whne you create the
latter. in the first form create a
public method that will receive the ID
from thre selected tree, then the method
will retrieve the data and populate
the listview


Great! It worked! It took me some moments to figure out what "pass a
reference to the FormTreeView" means...

So, in Form1 (the form with the listview) I wrote:

FormTreeView ftv = new FormTreeView();
ftv.MyParentForm = this;

and added a method "fillListViewAddress"
Then, in the FormTreeView class I wrote:

public InstituteAdministrator MyParentForm;

and added the method:

internal void dataTreeView1_AfterSelect(object sender,
System.Windows.Forms.TreeViewEventArgs e)
{
MyParentForm.fillListViewAddress(e.Node.Tag.ToStri ng());
}

This seems to do what I have hoped for. Thanks a lot!

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.