By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,238 Members | 1,804 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,238 IT Pros & Developers. It's quick & easy.

Array count=3 1 sec, count=0 the next?!?!

P: n/a

Hey guys,

I'm getting really annoyed with this array... After selecting some items
from a list view, I take the selected text from the first column and store
it in an array, I then pass this data back to the parent of this window,
which then takes this list (of filenames) and downloads them to a scanner.

I step through the child's array being filled with some paths of the data
that I selected in my list, then it all goes pear shaped. What's going wrong
is that when the the debugger steps back to the parent, and the selected
items array gets passed from the child to the parent, it's empty! From
stepping from ChildForm.cs "DialogResult = DialogResult.OK;" where my array
is populated with the data, to "m_SelectedItems =
frmPickListManage.SelectedItems;" where SelectedItems tells me my array has
a count of zero?!

Any help would be grately appreciated.

Thanks..
Dan.
//-------------------
// ParentForm.cs

//
// other code
//

FormPickListManagement frmPickListManage = new FormPickListManagement();

if ( frmPickListManage.ShowDialog() == DialogResult.OK )
{
ParentSelectedItems = frmPickListManage.SelectedItems;
DialogResult = DialogResult.OK;
}
else
{
DialogResult = DialogResult.Cancel;
}
//------------------
// ChildForm.cs

//
// other code
//

private ArrayList SelectItemsArray = new ArrayList();

public ArrayList SelectedItems
{

get
{
return SelectItemsArray;
}

}

private void button1_Click(object sender, System.EventArgs e)
{

//
// get the selected file list

ArrayList SelectItemsArray = new ArrayList();

foreach ( ListViewItem lvi in listViewPickingList.Items )
{
if ( lvi.Selected )
{
// text always returns with a filename and path as I expect
SelectItemsArray.Add ( lvi.SubItems[0].Text );
}
}
//
// get the main form to do the work

DialogResult = DialogResult.OK;

}

// NOTE: SelectItemsArray is not referenced anywhere else!
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
<"Dan =o\)" <danielbass [at] postmaster [dot] co [dot] uk>> wrote:
I'm getting really annoyed with this array... After selecting some items
from a list view, I take the selected text from the first column and store
it in an array, I then pass this data back to the parent of this window,
which then takes this list (of filenames) and downloads them to a scanner.

I step through the child's array being filled with some paths of the data
that I selected in my list, then it all goes pear shaped. What's going wrong
is that when the the debugger steps back to the parent, and the selected
items array gets passed from the child to the parent, it's empty! From
stepping from ChildForm.cs "DialogResult = DialogResult.OK;" where my array
is populated with the data, to "m_SelectedItems =
frmPickListManage.SelectedItems;" where SelectedItems tells me my array has
a count of zero?!


You're declaring a local variable called SelectedItemsArray as well as
the member variable SelectedItemsArray. (Not that either of them are
arrays - they're ArrayLists.) When in button1_Click, you're "looking
at" the local variable; when you step out of that method, you're
looking at the member variable again.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

P: n/a
I've been staring at this for ages wondering what the heck is going on...
Knew I had to be missing something simple but didn't think i was that DAFT!

Thanks.

Dan.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<"Dan =o\)" <danielbass [at] postmaster [dot] co [dot] uk>> wrote:
I'm getting really annoyed with this array... After selecting some items
from a list view, I take the selected text from the first column and
store
it in an array, I then pass this data back to the parent of this window,
which then takes this list (of filenames) and downloads them to a
scanner.

I step through the child's array being filled with some paths of the data
that I selected in my list, then it all goes pear shaped. What's going
wrong
is that when the the debugger steps back to the parent, and the selected
items array gets passed from the child to the parent, it's empty! From
stepping from ChildForm.cs "DialogResult = DialogResult.OK;" where my
array
is populated with the data, to "m_SelectedItems =
frmPickListManage.SelectedItems;" where SelectedItems tells me my array
has
a count of zero?!


You're declaring a local variable called SelectedItemsArray as well as
the member variable SelectedItemsArray. (Not that either of them are
arrays - they're ArrayLists.) When in button1_Click, you're "looking
at" the local variable; when you step out of that method, you're
looking at the member variable again.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.