WinForms Interaction

  • Thread starter Ignacio Estrada via DotNetMonster.com
  • Start date
I

Ignacio Estrada via DotNetMonster.com

Hi, I want to have interactions between two forms. A will sample with next
lines:

1. The program user has a main window with a Listview control on it
2. The user selects an item from the listview and selects some 'details'
option.
3. The program responds showing a child window with details for item
selected on the main window.
4. In order the user selects previous/next item without have to close the
child window, there are two buttons (up/down) to navigate between items.

So my concern is even the child window is the active window the user
requires to see which item is selected on the Listview control of the main
window, so what I need is to keep highligted the selected item on the main
windows without the user select it as the active window.

Shuch behaviuor is exactly the same as the Events Viewer Windows OS tool.

I will appreciatte your help.
 
M

Morten Wennevik

Hi Ignacio,

If you mean the Event Viewer vs its Properties, then you need a way for
both Parent and Child to know of eachother. If you pass a reference to
the Parent in the Constructor of the Child, the Child can call directly on
the Parent to notify change and which Item is displayed. Select a manual
window position for the child to keep it clear of the ListView.
 
I

Ignacio Estrada via DotNetMonster.com

Hi Morten,

Thanks for answer, have you some example for this kind of program?

Thanks again.
 
M

Morten Wennevik

Hi,

This might get you started...

using System.Windows.Forms;

class Parent : Form
{
private Child childRef;

private void menuProperties_Click(object sender, EventArgs e)
{
if(childRef == null)
childRef = new Child(this);

// get whatever item is selected
// itemReference = myListBox.SelectedItem

childRef.Show();
childRef.ShowProperties(itemReference);
}

public void NewItem(bool down)
{
if(down)
// set next item in the list as selected
else
// set previous item in the list as selected

// get the selected item
// itemReference = myListBox.SelectedItem
childRef.ShowProperties(itemReference);
}
}


class Child : Form
{
private Parent p;

public Child(Parent p)
{
this.p = p;
}

private void DownButton_Click(object sender, EventArgs e)
{
p.NewItem(true);
}

private void UpButton_Click(object sender, EventArgs e)
{
p.NewItem(false);
}

public void ShowProperties(Item i)
{
// get properties for i and display them
}

}
 
I

Ignacio Estrada via DotNetMonster.com

Man, I forget to say you I am using VB instead of C# and I can not do the
translation to VB. So please could you write this sample on VB for me ?
 
M

Morten Wennevik

Sorry,

My VB is too bad for me to dare write it in public :(
The basic algoritm is to ...

1) Create a Parent class and a Child class.
2) Create a Child constructor that accepts a Parent as an argument
3) In the Parent class create a public method for changing selected item
(NewItem)
4) When you need to see the properties, create a Child object using the
overloaded constructor (new Child(this)). Store the reference to this
Child for later use. Call on the Child to show properties for the
selected item (pass an item reference).
5) When in the Child you need to change the selected item, call the Parent
(NewItem). The parent will then call Child with a reference to the new
item.

You may also check if the child reference is valid on SelectedIndexChanged
for the ListBox, if it is not null this means the properties dialog is
open and call the child to show properties.
 
I

Ignacio Estrada via DotNetMonster.com

All rigth, I will try to translate to VB and I will contact you later on.

I apprecciate so much your help !!
 
G

Guest

Morten,

I'm trying to do this same thing, but I am using c++ and header files. When
I try to create a Parent member in my child form it says it doesn't know what
it is. I think because I have each file calling each other and the headers
are getting confused. Only the first class recognizes the second. But the
second doesn't recognize the first. Please help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top