Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27349

Changing a Cell in a ListView with text from another form.

$
0
0
I have two forms. One contains a ListView (frmMain). I want the user to click on a line (Item) in the ListView and cause a new form to pop up. The user can then enter text in a textbox on the popup form and click an Update button.

Then the new text will be placed in a cell in the ListView in the item clicked.

The Problem, I can't seem to put the text in the ListView cell. I know it is because I'm a dunce at OOP.

Here is how I do it, I am using the "SelectedIndexChanged" event to capture the ListViewItem that is clicked:

Dim lvItemSelected As ListViewItem = lv.SelectedItems(0)
[This is basically the row clicked in the ListView named "lv"]

Then I make the popup form visible so the user can enter text and click the Update button. In the button click I can pick out the text from the textbox just fine but when I try to place it in the correct cell in lv I get an error. Here is how I try to place it.

frmMain.lvItemSelected.SubItems(1).Text = txtBox.Text

It compiles OK but when I run it I get:

"NullReferenceException was unhandled
Object reference not set to an instance of an object"

I think the problem is lvItemSelected isn't "available" to the popup form. I declared lvItemSelected Public in frmMain.

I have found that if I place:
(1) lvItemSelected.SubItems(1).Text = "xxxx" in frmMain, xxxx will appear in the ListView where I want it. So lvItemSelected is hanging around in frmMain OK.

(2) I can add lblTest to frmMain then in the button click I do:
frmMain.lblTest.Text = "yyyy" I will get yyyy in lblTest so the popup form can access lblTest in frmMain

So I think I need a way to pass lvItemSelected to the popup form code or pass the new typed text back to the frmMain and update from there.

Any ideas? Or am I so far from OOP that I can't get there from here?

Thanks,
Pete

Viewing all articles
Browse latest Browse all 27349

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>