---
title: "How to interact with object in another method using C#?"  
description: "How to interact with object in another method using C#?"  
author: "Anonymous User"  
published: 2013-10-14  
updated: 2013-10-14  
canonical: https://www.mindstick.com/forum/1668/how-to-interact-with-object-in-another-method-using-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# How to interact with object in another method using C#?

I'm populating a [self](https://www.mindstick.com/articles/44535/smart-ways-to-secure-self-storage-facilities)-made *[Windows](https://www.mindstick.com/articles/311752/how-to-install-and-use-the-google-wifi-software-on-a-windows-or-mac-computer) [Explorer](https://www.mindstick.com/forum/34658/want-to-developed-windows-explorer-without-using-telerik) using [TreeView](https://www.mindstick.com/forum/1180/how-to-create-a-treeview-from-xml-file-in-c-sharp) & [ListView](https://www.mindstick.com/articles/12744/listview-in-android)*; and I'm currently working on Creating new Folder. What I want to do is when I press the "New Folder" [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net), a new listView Item would be added with the name "New folder". After that, let [users](https://www.mindstick.com/news/2244/issue-preventing-users-from-accessing-facebook-s-social-networking-platforms-has-been-resolved) type in the name of the folder by using BeginEdit() [method](https://www.mindstick.com/forum/166/webservice-method).

```
private void buttonNewFolder_Click(object sender, EventArgs e)
        {
            ListViewItem newFolder = listView1.Items.Add("New folder", 1);
            newFolder.BeginEdit();
        }

private void listView1_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            Directory.CreateDirectory("C:\"+e.Label); //for example
            // Now how can I change some properties of the "newFolder" listView Item in the above methods (buttonNewFolder_Click) ?
        }
```

\

In `listView1_AfterLabelEdit` method, i use `Directory.CreateDirectory("C:\"+e.Label);` statement to create a new folder. But now, i want to change some [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties) of the above "newFolder" ListViewItem (for example Tag, ToolTipItem.. - for another use). How can I interact with that ListView Item in `buttonNewFolder_Click` method ??? Really really hope you guys can help ! Thanks sooo much in [advanced](https://www.mindstick.com/articles/12993/5-advanced-features-for-your-odoo-ecommerce-theme) !

## Replies

### Reply by Anonymous User

`newFolder` lives within the scope of `buttonNewFolder_Click` only. Literally move it outside the method to make it more 'globally' accessible:

```
ListViewItem newFolder;

private void buttonNewFolder_Click(object sender, EventArgs e)
        {
            newFolder = listView1.Items.Add("New folder", 1);
            newFolder.BeginEdit();
        }


private void listView1_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            Directory.CreateDirectory("C:\"+e.Label); //for example
            //You now have access to newFolder here
        }
```


---

Original Source: https://www.mindstick.com/forum/1668/how-to-interact-with-object-in-another-method-using-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
