473,386 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

update listview

hi

i have a listview in my main program... what i want to do is

i want to call a dialog box with a list of materials
but when the user adds a material... i want the list view to update
automatically.
while keeping the dialog box open, allowing the user to keep adding
until they r finished

Nov 17 '05 #1
4 2761
To do this with events, your dialog form would define an Event that is fired
when it has a new item to add. When your dialog is created by the main form,
it would subscribe to this event with a handler that added the value passed
in the EventArg to the ListBox.

The other, and less preferred way, would be to have a public function on
your main form that is callable from the dialog anytime a new item is added
to the list. In order to do this, the dialog would simply need a reference to
the main form. Unfortunately though, this is less preferred given it requires
pretty tight coupling between the two sets of code which is generally not
preferred.

Brendan
"Brent Starkes" wrote:
hi

i have a listview in my main program... what i want to do is

i want to call a dialog box with a list of materials
but when the user adds a material... i want the list view to update
automatically.
while keeping the dialog box open, allowing the user to keep adding
until they r finished


Nov 17 '05 #2
thanks for the response

im a newbie at this... can u explain that first response a little further or
better yet point me in the right direction for an example piece of code...
"Brendan Grant" <gr****@NOSPAMdahat.com> wrote in message
news:1D**********************************@microsof t.com...
To do this with events, your dialog form would define an Event that is
fired
when it has a new item to add. When your dialog is created by the main
form,
it would subscribe to this event with a handler that added the value
passed
in the EventArg to the ListBox.

The other, and less preferred way, would be to have a public function on
your main form that is callable from the dialog anytime a new item is
added
to the list. In order to do this, the dialog would simply need a reference
to
the main form. Unfortunately though, this is less preferred given it
requires
pretty tight coupling between the two sets of code which is generally not
preferred.

Brendan
"Brent Starkes" wrote:
hi

i have a listview in my main program... what i want to do is

i want to call a dialog box with a list of materials
but when the user adds a material... i want the list view to update
automatically.
while keeping the dialog box open, allowing the user to keep adding
until they r finished


Nov 17 '05 #3
On the dialog side, you would define the following:
//The EventArgs derived class that contains a single extra property, the
name of the new item
public class NewItemEventArgs : EventArgs
{
private string newItemName;
public string NewItemName
{
get
{
return newItemName;
}
}
public NewItemEventArgs( string newItemName )
{
this.newItemName = newItemName;
}
}

//The delegate defining the signature of the event
public delegate void NewItemEventHandler(object sender, NewItemEventArgs
e);

//The actual event that is subscribed to and fired
public event NewItemEventHandler NewItem;

//What the dialog form calls when it wants to raise the event.
private void OnNewItem(string newItemName)
{
if( NewItem != null )
{
NewItem(this, new NewItemEventArgs( newItemName ) );
}
}

On the main form side, when you want to create the new form, you would do
the following:

DialogForm f = new DialogForm();
f.NewItem +=new DialogForm.NewItemEventHandler(f_NewItem);
f.ShowDialog();

What does all of this do? It starts by creating a new instance of the
DialogForm class, and later attaches a new NewItemEventHandler to the NewItem
event, so that whenever the NewItem event is fired, f_NewItem is called.
Finally, the dialog is shown.

One little note, f_NewItem is quite simple as you see below in which it gets
a reference to the NewItemEventArgs created when the event was raised,
accesses the NewItemName property and adds it to the ListBox.

private void f_NewItem(object sender, DialogForm.NewItemEventArgs e)
{
myListBox.Items.Add( e.NewItemName );
}

Back to the Dialog form real quick... how does all of that work? The
standard is that when an event is raised, it should pass an instance of
something that is or derives from the EventArgs class, in this case, we are
using NewItemEventArgs which as noted above simply defines an extra property.
You can easily expand on it to contain almost anything you want.

The delegate defines what the event looks like, that is to say, what values
it is able to carry with it when it is fired.

The actual event is quite simple, simply saying that you want an event of a
given name that uses a certain type of EventHandler (delegate).

Finally, OnNewItem which provides a safety mechanism when accessing the
handler. If you try to fire an event directly that doesn’t have any
subscribers, bad things happen, and in OnNewItem we check to see if anything
is subscribed with the != null, and if we have anything, we fire the event by
calling it with the arguments of the sender (this) and a new instance of
NewItemEventArgs whose constructor allows it to take a string which sets the
newItemName portion of the class.

Brendan
"Brent Starkes" wrote:
thanks for the response

im a newbie at this... can u explain that first response a little further or
better yet point me in the right direction for an example piece of code...
"Brendan Grant" <gr****@NOSPAMdahat.com> wrote in message
news:1D**********************************@microsof t.com...
To do this with events, your dialog form would define an Event that is
fired
when it has a new item to add. When your dialog is created by the main
form,
it would subscribe to this event with a handler that added the value
passed
in the EventArg to the ListBox.

The other, and less preferred way, would be to have a public function on
your main form that is callable from the dialog anytime a new item is
added
to the list. In order to do this, the dialog would simply need a reference
to
the main form. Unfortunately though, this is less preferred given it
requires
pretty tight coupling between the two sets of code which is generally not
preferred.

Brendan
"Brent Starkes" wrote:
hi

i have a listview in my main program... what i want to do is

i want to call a dialog box with a list of materials
but when the user adds a material... i want the list view to update
automatically.
while keeping the dialog box open, allowing the user to keep adding
until they r finished



Nov 17 '05 #4
thanks a lot brendan

"Brendan Grant" <gr****@NOSPAMdahat.com> wrote in message
news:B0**********************************@microsof t.com...
On the dialog side, you would define the following:
//The EventArgs derived class that contains a single extra property, the
name of the new item
public class NewItemEventArgs : EventArgs
{
private string newItemName;
public string NewItemName
{
get
{
return newItemName;
}
}
public NewItemEventArgs( string newItemName )
{
this.newItemName = newItemName;
}
}

//The delegate defining the signature of the event
public delegate void NewItemEventHandler(object sender, NewItemEventArgs
e);

//The actual event that is subscribed to and fired
public event NewItemEventHandler NewItem;

//What the dialog form calls when it wants to raise the event.
private void OnNewItem(string newItemName)
{
if( NewItem != null )
{
NewItem(this, new NewItemEventArgs( newItemName ) );
}
}

On the main form side, when you want to create the new form, you would do
the following:

DialogForm f = new DialogForm();
f.NewItem +=new DialogForm.NewItemEventHandler(f_NewItem);
f.ShowDialog();

What does all of this do? It starts by creating a new instance of the
DialogForm class, and later attaches a new NewItemEventHandler to the
NewItem
event, so that whenever the NewItem event is fired, f_NewItem is called.
Finally, the dialog is shown.

One little note, f_NewItem is quite simple as you see below in which it
gets
a reference to the NewItemEventArgs created when the event was raised,
accesses the NewItemName property and adds it to the ListBox.

private void f_NewItem(object sender, DialogForm.NewItemEventArgs e)
{
myListBox.Items.Add( e.NewItemName );
}

Back to the Dialog form real quick... how does all of that work? The
standard is that when an event is raised, it should pass an instance of
something that is or derives from the EventArgs class, in this case, we
are
using NewItemEventArgs which as noted above simply defines an extra
property.
You can easily expand on it to contain almost anything you want.

The delegate defines what the event looks like, that is to say, what
values
it is able to carry with it when it is fired.

The actual event is quite simple, simply saying that you want an event of
a
given name that uses a certain type of EventHandler (delegate).

Finally, OnNewItem which provides a safety mechanism when accessing the
handler. If you try to fire an event directly that doesn't have any
subscribers, bad things happen, and in OnNewItem we check to see if
anything
is subscribed with the != null, and if we have anything, we fire the event
by
calling it with the arguments of the sender (this) and a new instance of
NewItemEventArgs whose constructor allows it to take a string which sets
the
newItemName portion of the class.

Brendan
"Brent Starkes" wrote:
thanks for the response

im a newbie at this... can u explain that first response a little further
or
better yet point me in the right direction for an example piece of
code...
"Brendan Grant" <gr****@NOSPAMdahat.com> wrote in message
news:1D**********************************@microsof t.com...
> To do this with events, your dialog form would define an Event that is
> fired
> when it has a new item to add. When your dialog is created by the main
> form,
> it would subscribe to this event with a handler that added the value
> passed
> in the EventArg to the ListBox.
>
> The other, and less preferred way, would be to have a public function
> on
> your main form that is callable from the dialog anytime a new item is
> added
> to the list. In order to do this, the dialog would simply need a
> reference
> to
> the main form. Unfortunately though, this is less preferred given it
> requires
> pretty tight coupling between the two sets of code which is generally
> not
> preferred.
>
> Brendan
>
>
> "Brent Starkes" wrote:
>
>> hi
>>
>> i have a listview in my main program... what i want to do is
>>
>> i want to call a dialog box with a list of materials
>> but when the user adds a material... i want the list view to update
>> automatically.
>> while keeping the dialog box open, allowing the user to keep adding
>> until they r finished
>>
>>
>>
>>
>>
>>


Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Lee | last post by:
Hi, I have a windows application that uses the listview to display about 50 items in detailed view - 4 columns. The first column is static and other columns will be updated in 100-1000ms - it...
1
by: Dave | last post by:
I have a listview control in a form, and I use the mousemove event (to set a tooltip). This worked fine in VS2003, but when I ported it to VS2005 I found that when the mouse hovers over a populated...
2
by: senfo | last post by:
I'm using a ListView control to display pictures similarly to how Windows Explorer displays pictures in "Thumbnails" view. The images are stored in an ImageList component. I would like to provide...
1
by: Bruce | last post by:
Hi I am implementing a simple app in C# where I show a list of files in a form. (set of ListViewItems in ListView.Items) I create these ListViewItems using an arraylist of my custom objects...
1
by: Jeff | last post by:
I have a list view with items. An item is clicked and I have a form to change this data. How can I update the listview row in the list view control.
0
by: kaibest | last post by:
i have one ListView with 5 rows and 100+ collums. i need to do kind of search system... i have one text field, when i start type something i want listView to update depending on what i type... i'm...
0
by: twoSeven | last post by:
hi, Here is what i want to do. I am making a file and folder browser similar to Windows Explorer with a treeview and listview.. In that, i get icons and thumbnails of a particular file/folder from...
0
by: shapper | last post by:
Hello, I created a ListView at runtime by implementing the ITemplate. Inside my Edit Item template I have custom control, named MyForm, that contains two buttons: "Update" and "Cancel" ...
25
by: news.microsoft.com | last post by:
Hi all, First post here. I'm porting an application I wrote in VB6, over to VB.NET 2005. It could be said I'm really struggling with some (most!) of the syntax of VB.NET 2005, but I'm getting...
0
by: thami | last post by:
hello my probleme is : i have a listview with a datapager control that allow to paginate my listview the all in updatepanel i want to be able to paginate from one rows to other in the listview...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.