473,387 Members | 1,520 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,387 software developers and data experts.

Accessing control on one form from another

I have a form with a listview and an edit button named Form1. When
the edit button is clicked, a dialog box containing some textboxes
should appear and the textboxes should be filled with data from the
currently selected listview item. The dialog form is called FormEdit.

How do I access the listview object on my main form the dialog form?

// The main form, in a file called Form1.cs... contains the listview
and the edit button

namespace WindowsApplication17
{
public partial class Form1 : Form
{

public Form1()
{
ListViewItem lvItem = new ListViewItem(textBoxLastName.Text, 0);
listView1.Items.Add(lvItem);
}
private void btnEditRecord_Click(object sender, EventArgs e)
{
FormEdit formEdit = new FormEdit();
formEdit.ShowDialog();
}
}

}

// The edit form, in a filed called Form2.cs

namespace WindowsApplication17
{
public partial class FormEdit : Form
{
public FormEdit()
{
InitializeComponent();
}

private void FormEdit_Load(object sender, EventArgs e)
{
// here is where I want to pull the data from the listview
on Form1 and populate the textboxes
// on this dialog with information from the main form
}
}
}

I can access the Form1 object by just typing it "Form1", but there is
no access to the listview (ie. Form1.listView)

Sep 14 '07 #1
3 5958
ma******@gmail.com wrote:
I have a form with a listview and an edit button named Form1. When
the edit button is clicked, a dialog box containing some textboxes
should appear and the textboxes should be filled with data from the
currently selected listview item. The dialog form is called FormEdit.

How do I access the listview object on my main form the dialog form?
Here's the short version:
http://tinyurl.com/2lguxp

In case the long version gets broken by line-wrapping:
http://groups.google.com/groups/sear...=Search+Groups
Sep 14 '07 #2
On Sep 13, 9:50 pm, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.comwrote:
markl...@gmail.com wrote:
I have a form with a listview and an edit button named Form1. When
the edit button is clicked, a dialog box containing some textboxes
should appear and the textboxes should be filled with data from the
currently selected listview item. The dialog form is called FormEdit.
How do I access the listview object on my main form the dialog form?

Here's the short version:http://tinyurl.com/2lguxp

In case the long version gets broken by line-wrapping:http://groups.google.com/groups/sear...+form+another+...
I'm probably doing it wrong, but here is what I tried:

On the main form where I call the dialog box, I changed:
FormEdit formEdit = new FormEdit();
to
FormEdit formEdit = new FormEdit(this);

And in the constructor of the dialog box I changed:
public FormEdit()
{
InitializeComponent();
}

to

public FormEdit(Form parent)
{
InitializeComponent()
}

but I still can't seem to access parent.listView1, even after making
it public on the main form

What am I doing wrong here?

Sep 14 '07 #3
On Sep 13, 10:09 pm, markl...@gmail.com wrote:
On Sep 13, 9:50 pm, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.comwrote:
markl...@gmail.com wrote:
I have a form with a listview and an edit button named Form1. When
the edit button is clicked, a dialog box containing some textboxes
should appear and the textboxes should be filled with data from the
currently selected listview item. The dialog form is called FormEdit.
How do I access the listview object on my main form the dialog form?
Here's the short version:http://tinyurl.com/2lguxp
In case the long version gets broken by line-wrapping:http://groups.google.com/groups/sear...+form+another+...

I'm probably doing it wrong, but here is what I tried:

On the main form where I call the dialog box, I changed:
FormEdit formEdit = new FormEdit();
to
FormEdit formEdit = new FormEdit(this);

And in the constructor of the dialog box I changed:
public FormEdit()
{
InitializeComponent();

}

to

public FormEdit(Form parent)
{
InitializeComponent()

}

but I still can't seem to access parent.listView1, even after making
it public on the main form

What am I doing wrong here?
Doh, I was passing a new Form rather than my own Form1 object. I've
got it now, thank you.

Sep 14 '07 #4

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

Similar topics

3
by: Tom Meuzelaar | last post by:
Hello: I'm using VB6 in VS enterprise. I'd like to place an HTML form inside a VB container, have a user fill out the form information, click a submit button, and then have the program capture...
1
by: JC | last post by:
How do I extract data from a form into the main form for processing? For instance, I have several image files in a form called images(images.frm), indexed from 0 to 99, and I want to import these...
3
by: Vivek Sharma | last post by:
Hi, I have created a dropdownlist as a web user control. I am using its multiple instances on the webpage. How do I access the selectedValue of each instance? All the instances have different...
1
by: tmaster | last post by:
Within a class, can I create a property that is a listview? Here's what I tried, but it doesn't seem to work: '------------ create property to give the second form access to the first form's...
9
by: Blake Weaver | last post by:
Ok, this is probably a no-brainer for most of you but its escaping me and I can't even seem to find the answer in any documentation. How do you access a friend variable of one class, from another...
3
by: Tim Fitzgerald | last post by:
Hello all, I have no problem accessing another form in my app.. however, when I try to access a ListView on a different form, I come up empty... Basically, Dim pForm As New frmMain Dim iCount...
0
by: Geraldine Hobley | last post by:
Hello I have a problem whereby I have a treeview control on one form called projecttree and I wish to clea the nodes from this control in another form The form that contains the treeview is...
0
by: aakash | last post by:
Hello Guys I am upsizing ms access project to give it a ms sql connectivity I am having problem in accessing form control values in ms sql function CREATE FUNCTION "ReportList DateRange"() ...
3
by: =?Utf-8?B?dmJ0cnlpbmc=?= | last post by:
Background: I have a windows form called 'frmMain'. On this form, I have a LABEL control called 'lblWorkStatus', and it's property is set to PUBLIC. On another form, I have a process that checks...
2
by: San24 | last post by:
Guys, Let me explain the application I have - Form > Main Tab Control > Main Tab Page > User Control > Sub Tab Control > Sub Tab Page > User Control > Contols/Text Box. Form - The main...
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: 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$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.