Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / April 2005

Tip: Looking for answers? Try searching our database.

WinForms Interaction

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ignacio Estrada - 13 Feb 2005 16:41 GMT
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.
Morten Wennevik - 14 Feb 2005 09:57 GMT
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.

Signature

Happy Coding!
Morten Wennevik [C# MVP]

Ignacio Estrada - 18 Feb 2005 06:10 GMT
Hi Morten,

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

Thanks again.
Morten Wennevik - 18 Feb 2005 10:14 GMT
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
    }

}

Signature

Happy Coding!
Morten Wennevik [C# MVP]

Ignacio Estrada - 19 Feb 2005 22:58 GMT
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 ?
Morten Wennevik - 21 Feb 2005 10:26 GMT
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.

> 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 ?

Signature

Happy Coding!
Morten Wennevik [C# MVP]

Ignacio Estrada - 22 Feb 2005 06:28 GMT
All rigth, I will try to translate to VB and I will contact you later on.

I apprecciate so much your help !!
GrkEngineer - 21 Apr 2005 19:21 GMT
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.

> Hi,
>
[quoted text clipped - 56 lines]
>
> }

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.