Hello,

I have a ListView at one form and in that ListView are loaded articles
according to the previous chosed Id on the previous form. Thus I had to use
the Clear method to delete the articles from the listView before the user
chose another Id. The problem is that the ListView.Items.Clear method throws
a NullReferenceException when the listView contains no article at the first
time. Why does the clear method throws a NullReferenceException?? - The Clear
method from the listBox does not throw no NullReferenceException even if no
item is in the listBox...

thx

robert

Re: ListView.Items.Clear?? by Daniel

Daniel
Sun Jan 02 08:41:29 CST 2005

Assuming you are running SP2
(http://wiki.opennetcf.org/ow.asp?CompactFrameworkFAQ%2FDeterminingVersion)...

...can you post a small sample that reproduces the problem?

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"robert" <robert@discussions.microsoft.com> wrote in message
news:9F4F74C2-0641-4C41-8F18-C5D484B08A58@microsoft.com...
> Hello,
>
> I have a ListView at one form and in that ListView are loaded articles
> according to the previous chosed Id on the previous form. Thus I had to
> use
> the Clear method to delete the articles from the listView before the user
> chose another Id. The problem is that the ListView.Items.Clear method
> throws
> a NullReferenceException when the listView contains no article at the
> first
> time. Why does the clear method throws a NullReferenceException?? - The
> Clear
> method from the listBox does not throw no NullReferenceException even if
> no
> item is in the listBox...
>
> thx
>
> robert



Re: ListView.Items.Clear?? by robert

robert
Sun Jan 02 13:19:05 CST 2005

Hello,

The following clear call in the LoadTitle method produces the
NullReferenceException:

public void LoadTitle()
{

listView1.Items.Clear();

ArrayList arrayList = new ArrayList();
dtabProblems = database.LoadProblemTitles(new Guid(Replication.getJobId()));
for(int i = 0; i < dtabProblems.Rows.Count; i++)
{
string[] problems = new string[2];
problems[0] = dtabProblems.Rows[i]["Titel"].ToString();
problems[1] = dtabProblems.Rows[i]["Category"].ToString();
listView1.Items.Add(new ListViewItem(problems));
}

}

The LoadProblemTitles returns a DataTable with the corresponding titles. The
type of dtabProblems is DataTable. The data of the DataTable should then be
displayed with the for-sequence in the listView1.

Anybody an idea why a NullReferenceException occur, when I add the
listView1.Items.Clear call to the method??:(

thx

robert

Re: ListView.Items.Clear?? by Daniel

Daniel
Sun Jan 02 13:37:04 CST 2005

Where are you calling the method from? Has the listview been created (has it
got columns etc setup)? Have you tried adding a try..catch around the
listView1.Items.Clear() to make sure it is that line that throws?

If you post a small sample (not just a method) that demonstrates the problem
I can try to debug it (e.g. calling clear from a button click with no other
statements in it). A simple repro I have works fine in the PPC emulator
(what are you testing this on?).

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"robert" <robert@discussions.microsoft.com> wrote in message
news:83B98049-B807-49DA-9F08-DC2FE7066BC8@microsoft.com...
> Hello,
>
> The following clear call in the LoadTitle method produces the
> NullReferenceException:
>
> public void LoadTitle()
> {
>
> listView1.Items.Clear();
>
> ArrayList arrayList = new ArrayList();
> dtabProblems = database.LoadProblemTitles(new
> Guid(Replication.getJobId()));
> for(int i = 0; i < dtabProblems.Rows.Count; i++)
> {
> string[] problems = new string[2];
> problems[0] = dtabProblems.Rows[i]["Titel"].ToString();
> problems[1] = dtabProblems.Rows[i]["Category"].ToString();
> listView1.Items.Add(new ListViewItem(problems));
> }
>
> }
>
> The LoadProblemTitles returns a DataTable with the corresponding titles.
> The
> type of dtabProblems is DataTable. The data of the DataTable should then
> be
> displayed with the for-sequence in the listView1.
>
> Anybody an idea why a NullReferenceException occur, when I add the
> listView1.Items.Clear call to the method??:(
>
> thx
>
> robert



Re: ListView.Items.Clear?? by robert

robert
Sun Jan 02 15:33:05 CST 2005

Hello,

It is a little problem to post it in a sample because this method is part of
a whole application.
I initialize the two columns in the fields part before the constructor of
the form:

private myColumnHeader Title = new myColumnHeader("Title", 142,
HorizontalAlignment.Center,true);
private myColumnHeader category = new myColumnHeader("Category", 68,
HorizontalAlignment.Left, true);

in the constructor of the form I add the columns to the listView:

listView1.Columns.Add(Title);
listView1.Columns.Add(category);
listView1.View = System.Windows.Forms.View.Details;
listView1.FullRowSelect = true;

this lines are placed after the call of the InitializeComponent method. The
previous posted method is called also in the constructor of the form but
after the above lines.

thats all. the LoadProblemTitles is placed in the data.cs file and retrieves
the titles and the corresponding category and save these data in the
dtabProblems dataTable.

Does this help you? - I did not find the error..:( I must be this code line
because when I omit this line the code works without problems but the
listView is not cleared after every loading. It must also be this line
because I placed a MessageBox after the clear statement and the MessageBox
does not appear when I execute the code.

Have you got any idea?

robert






"Daniel Moth" wrote:

> Where are you calling the method from? Has the listview been created (has it
> got columns etc setup)? Have you tried adding a try..catch around the
> listView1.Items.Clear() to make sure it is that line that throws?
>
> If you post a small sample (not just a method) that demonstrates the problem
> I can try to debug it (e.g. calling clear from a button click with no other
> statements in it). A simple repro I have works fine in the PPC emulator
> (what are you testing this on?).
>
> Cheers
> Daniel
> --
> http://www.danielmoth.com/Blog/
>
>
> "robert" <robert@discussions.microsoft.com> wrote in message
> news:83B98049-B807-49DA-9F08-DC2FE7066BC8@microsoft.com...
> > Hello,
> >
> > The following clear call in the LoadTitle method produces the
> > NullReferenceException:
> >
> > public void LoadTitle()
> > {
> >
> > listView1.Items.Clear();
> >
> > ArrayList arrayList = new ArrayList();
> > dtabProblems = database.LoadProblemTitles(new
> > Guid(Replication.getJobId()));
> > for(int i = 0; i < dtabProblems.Rows.Count; i++)
> > {
> > string[] problems = new string[2];
> > problems[0] = dtabProblems.Rows[i]["Titel"].ToString();
> > problems[1] = dtabProblems.Rows[i]["Category"].ToString();
> > listView1.Items.Add(new ListViewItem(problems));
> > }
> >
> > }
> >
> > The LoadProblemTitles returns a DataTable with the corresponding titles.
> > The
> > type of dtabProblems is DataTable. The data of the DataTable should then
> > be
> > displayed with the for-sequence in the listView1.
> >
> > Anybody an idea why a NullReferenceException occur, when I add the
> > listView1.Items.Clear call to the method??:(
> >
> > thx
> >
> > robert
>
>
>

Re: ListView.Items.Clear?? by Daniel

Daniel
Sun Jan 02 15:53:25 CST 2005

Robert, it is essential for your own benefit and when asking help from
others to be able to provide a small reproducible sample. By isolating the
problem you can zoom in on the solution. For example, where is this
myColumnHeader class?

Anyway, we can continue the question game. Have you got any event handlers
(e.g. SelctedIndexChanged) attached to the listview? These will likely fire
when you clear the listview; stick a breakpoint in there or even better wrap
the method with a try..catch to see if that is the case.

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"robert" <robert@discussions.microsoft.com> wrote in message
news:6959B290-7292-4C9B-AAD1-826F2FD25747@microsoft.com...
> Hello,
>
> It is a little problem to post it in a sample because this method is part
> of
> a whole application.
> I initialize the two columns in the fields part before the constructor of
> the form:
>
> private myColumnHeader Title = new myColumnHeader("Title", 142,
> HorizontalAlignment.Center,true);
> private myColumnHeader category = new myColumnHeader("Category", 68,
> HorizontalAlignment.Left, true);
>
> in the constructor of the form I add the columns to the listView:
>
> listView1.Columns.Add(Title);
> listView1.Columns.Add(category);
> listView1.View = System.Windows.Forms.View.Details;
> listView1.FullRowSelect = true;
>
> this lines are placed after the call of the InitializeComponent method.
> The
> previous posted method is called also in the constructor of the form but
> after the above lines.
>
> thats all. the LoadProblemTitles is placed in the data.cs file and
> retrieves
> the titles and the corresponding category and save these data in the
> dtabProblems dataTable.
>
> Does this help you? - I did not find the error..:( I must be this code
> line
> because when I omit this line the code works without problems but the
> listView is not cleared after every loading. It must also be this line
> because I placed a MessageBox after the clear statement and the MessageBox
> does not appear when I execute the code.
>
> Have you got any idea?
>
> robert
>
>
>
>
>
>
> "Daniel Moth" wrote:
>
>> Where are you calling the method from? Has the listview been created (has
>> it
>> got columns etc setup)? Have you tried adding a try..catch around the
>> listView1.Items.Clear() to make sure it is that line that throws?
>>
>> If you post a small sample (not just a method) that demonstrates the
>> problem
>> I can try to debug it (e.g. calling clear from a button click with no
>> other
>> statements in it). A simple repro I have works fine in the PPC emulator
>> (what are you testing this on?).
>>
>> Cheers
>> Daniel
>> --
>> http://www.danielmoth.com/Blog/
>>
>>
>> "robert" <robert@discussions.microsoft.com> wrote in message
>> news:83B98049-B807-49DA-9F08-DC2FE7066BC8@microsoft.com...
>> > Hello,
>> >
>> > The following clear call in the LoadTitle method produces the
>> > NullReferenceException:
>> >
>> > public void LoadTitle()
>> > {
>> >
>> > listView1.Items.Clear();
>> >
>> > ArrayList arrayList = new ArrayList();
>> > dtabProblems = database.LoadProblemTitles(new
>> > Guid(Replication.getJobId()));
>> > for(int i = 0; i < dtabProblems.Rows.Count; i++)
>> > {
>> > string[] problems = new string[2];
>> > problems[0] = dtabProblems.Rows[i]["Titel"].ToString();
>> > problems[1] = dtabProblems.Rows[i]["Category"].ToString();
>> > listView1.Items.Add(new ListViewItem(problems));
>> > }
>> >
>> > }
>> >
>> > The LoadProblemTitles returns a DataTable with the corresponding
>> > titles.
>> > The
>> > type of dtabProblems is DataTable. The data of the DataTable should
>> > then
>> > be
>> > displayed with the for-sequence in the listView1.
>> >
>> > Anybody an idea why a NullReferenceException occur, when I add the
>> > listView1.Items.Clear call to the method??:(
>> >
>> > thx
>> >
>> > robert
>>
>>
>>



Re: ListView.Items.Clear?? by robert

robert
Sun Jan 02 17:43:01 CST 2005

Hello,

Sorry for the effort, if the following information does not help, I would
develop a little sample with the corresponding code. The myColumnHeader
works, because I also use it on another form. I think I have this from a code
sample of Chris Tacke. The classes for the column header are placed in the
same file as the form. I have a SelectedIndex Change event with the following
code:

private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
{
LoadOneProblem((string)dtabProblems.Rows[listView1.SelectedIndices[0]][0]);
title =
(string)dtabProblems.Rows[listView1.SelectedIndices[0]][0];

}

I extract the value of clicked line in the ListView (of the first column)
because then a next form with details should be displayed automatically after
the user clicks on on title of the listview. Could be the extracting after
the indices the problem for the null reference exception? - But I do not know
how I could realize the view of the details of the selected title in another
way? - I do not want to realize it with a extra button.

robert


"Daniel Moth" wrote:

> Robert, it is essential for your own benefit and when asking help from
> others to be able to provide a small reproducible sample. By isolating the
> problem you can zoom in on the solution. For example, where is this
> myColumnHeader class?
>
> Anyway, we can continue the question game. Have you got any event handlers
> (e.g. SelctedIndexChanged) attached to the listview? These will likely fire
> when you clear the listview; stick a breakpoint in there or even better wrap
> the method with a try..catch to see if that is the case.
>
> Cheers
> Daniel
> --
> http://www.danielmoth.com/Blog/
>
>
> "robert" <robert@discussions.microsoft.com> wrote in message
> news:6959B290-7292-4C9B-AAD1-826F2FD25747@microsoft.com...
> > Hello,
> >
> > It is a little problem to post it in a sample because this method is part
> > of
> > a whole application.
> > I initialize the two columns in the fields part before the constructor of
> > the form:
> >
> > private myColumnHeader Title = new myColumnHeader("Title", 142,
> > HorizontalAlignment.Center,true);
> > private myColumnHeader category = new myColumnHeader("Category", 68,
> > HorizontalAlignment.Left, true);
> >
> > in the constructor of the form I add the columns to the listView:
> >
> > listView1.Columns.Add(Title);
> > listView1.Columns.Add(category);
> > listView1.View = System.Windows.Forms.View.Details;
> > listView1.FullRowSelect = true;
> >
> > this lines are placed after the call of the InitializeComponent method.
> > The
> > previous posted method is called also in the constructor of the form but
> > after the above lines.
> >
> > thats all. the LoadProblemTitles is placed in the data.cs file and
> > retrieves
> > the titles and the corresponding category and save these data in the
> > dtabProblems dataTable.
> >
> > Does this help you? - I did not find the error..:( I must be this code
> > line
> > because when I omit this line the code works without problems but the
> > listView is not cleared after every loading. It must also be this line
> > because I placed a MessageBox after the clear statement and the MessageBox
> > does not appear when I execute the code.
> >
> > Have you got any idea?
> >
> > robert
> >
> >
> >
> >
> >
> >
> > "Daniel Moth" wrote:
> >
> >> Where are you calling the method from? Has the listview been created (has
> >> it
> >> got columns etc setup)? Have you tried adding a try..catch around the
> >> listView1.Items.Clear() to make sure it is that line that throws?
> >>
> >> If you post a small sample (not just a method) that demonstrates the
> >> problem
> >> I can try to debug it (e.g. calling clear from a button click with no
> >> other
> >> statements in it). A simple repro I have works fine in the PPC emulator
> >> (what are you testing this on?).
> >>
> >> Cheers
> >> Daniel
> >> --
> >> http://www.danielmoth.com/Blog/
> >>
> >>
> >> "robert" <robert@discussions.microsoft.com> wrote in message
> >> news:83B98049-B807-49DA-9F08-DC2FE7066BC8@microsoft.com...
> >> > Hello,
> >> >
> >> > The following clear call in the LoadTitle method produces the
> >> > NullReferenceException:
> >> >
> >> > public void LoadTitle()
> >> > {
> >> >
> >> > listView1.Items.Clear();
> >> >
> >> > ArrayList arrayList = new ArrayList();
> >> > dtabProblems = database.LoadProblemTitles(new
> >> > Guid(Replication.getJobId()));
> >> > for(int i = 0; i < dtabProblems.Rows.Count; i++)
> >> > {
> >> > string[] problems = new string[2];
> >> > problems[0] = dtabProblems.Rows[i]["Titel"].ToString();
> >> > problems[1] = dtabProblems.Rows[i]["Category"].ToString();
> >> > listView1.Items.Add(new ListViewItem(problems));
> >> > }
> >> >
> >> > }
> >> >
> >> > The LoadProblemTitles returns a DataTable with the corresponding
> >> > titles.
> >> > The
> >> > type of dtabProblems is DataTable. The data of the DataTable should
> >> > then
> >> > be
> >> > displayed with the for-sequence in the listView1.
> >> >
> >> > Anybody an idea why a NullReferenceException occur, when I add the
> >> > listView1.Items.Clear call to the method??:(
> >> >
> >> > thx
> >> >
> >> > robert
> >>
> >>
> >>
>
>
>

Re: ListView.Items.Clear?? by Daniel

Daniel
Sun Jan 02 17:52:06 CST 2005

So what happens if you insert the following at the top of
listView1_SelectedIndexChanged:
if (listView.SelectedIndices.Count == 0){
return;
}

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"robert" <robert@discussions.microsoft.com> wrote in message
news:BD5AB19F-89D0-457E-B061-366507720189@microsoft.com...
> Hello,
>
> Sorry for the effort, if the following information does not help, I would
> develop a little sample with the corresponding code. The myColumnHeader
> works, because I also use it on another form. I think I have this from a
> code
> sample of Chris Tacke. The classes for the column header are placed in the
> same file as the form. I have a SelectedIndex Change event with the
> following
> code:
>
> private void listView1_SelectedIndexChanged(object sender,
> System.EventArgs e)
> {
> LoadOneProblem((string)dtabProblems.Rows[listView1.SelectedIndices[0]][0]);
> title =
> (string)dtabProblems.Rows[listView1.SelectedIndices[0]][0];
>
> }
>
> I extract the value of clicked line in the ListView (of the first column)
> because then a next form with details should be displayed automatically
> after
> the user clicks on on title of the listview. Could be the extracting after
> the indices the problem for the null reference exception? - But I do not
> know
> how I could realize the view of the details of the selected title in
> another
> way? - I do not want to realize it with a extra button.
>
> robert
>
>
> "Daniel Moth" wrote:
>
>> Robert, it is essential for your own benefit and when asking help from
>> others to be able to provide a small reproducible sample. By isolating
>> the
>> problem you can zoom in on the solution. For example, where is this
>> myColumnHeader class?
>>
>> Anyway, we can continue the question game. Have you got any event
>> handlers
>> (e.g. SelctedIndexChanged) attached to the listview? These will likely
>> fire
>> when you clear the listview; stick a breakpoint in there or even better
>> wrap
>> the method with a try..catch to see if that is the case.
>>
>> Cheers
>> Daniel
>> --
>> http://www.danielmoth.com/Blog/
>>
>>
>> "robert" <robert@discussions.microsoft.com> wrote in message
>> news:6959B290-7292-4C9B-AAD1-826F2FD25747@microsoft.com...
>> > Hello,
>> >
>> > It is a little problem to post it in a sample because this method is
>> > part
>> > of
>> > a whole application.
>> > I initialize the two columns in the fields part before the constructor
>> > of
>> > the form:
>> >
>> > private myColumnHeader Title = new myColumnHeader("Title", 142,
>> > HorizontalAlignment.Center,true);
>> > private myColumnHeader category = new myColumnHeader("Category", 68,
>> > HorizontalAlignment.Left, true);
>> >
>> > in the constructor of the form I add the columns to the listView:
>> >
>> > listView1.Columns.Add(Title);
>> > listView1.Columns.Add(category);
>> > listView1.View = System.Windows.Forms.View.Details;
>> > listView1.FullRowSelect = true;
>> >
>> > this lines are placed after the call of the InitializeComponent method.
>> > The
>> > previous posted method is called also in the constructor of the form
>> > but
>> > after the above lines.
>> >
>> > thats all. the LoadProblemTitles is placed in the data.cs file and
>> > retrieves
>> > the titles and the corresponding category and save these data in the
>> > dtabProblems dataTable.
>> >
>> > Does this help you? - I did not find the error..:( I must be this code
>> > line
>> > because when I omit this line the code works without problems but the
>> > listView is not cleared after every loading. It must also be this line
>> > because I placed a MessageBox after the clear statement and the
>> > MessageBox
>> > does not appear when I execute the code.
>> >
>> > Have you got any idea?
>> >
>> > robert
>> >
>> >
>> >
>> >
>> >
>> >
>> > "Daniel Moth" wrote:
>> >
>> >> Where are you calling the method from? Has the listview been created
>> >> (has
>> >> it
>> >> got columns etc setup)? Have you tried adding a try..catch around the
>> >> listView1.Items.Clear() to make sure it is that line that throws?
>> >>
>> >> If you post a small sample (not just a method) that demonstrates the
>> >> problem
>> >> I can try to debug it (e.g. calling clear from a button click with no
>> >> other
>> >> statements in it). A simple repro I have works fine in the PPC
>> >> emulator
>> >> (what are you testing this on?).
>> >>
>> >> Cheers
>> >> Daniel
>> >> --
>> >> http://www.danielmoth.com/Blog/
>> >>
>> >>
>> >> "robert" <robert@discussions.microsoft.com> wrote in message
>> >> news:83B98049-B807-49DA-9F08-DC2FE7066BC8@microsoft.com...
>> >> > Hello,
>> >> >
>> >> > The following clear call in the LoadTitle method produces the
>> >> > NullReferenceException:
>> >> >
>> >> > public void LoadTitle()
>> >> > {
>> >> >
>> >> > listView1.Items.Clear();
>> >> >
>> >> > ArrayList arrayList = new ArrayList();
>> >> > dtabProblems = database.LoadProblemTitles(new
>> >> > Guid(Replication.getJobId()));
>> >> > for(int i = 0; i < dtabProblems.Rows.Count; i++)
>> >> > {
>> >> > string[] problems = new string[2];
>> >> > problems[0] = dtabProblems.Rows[i]["Titel"].ToString();
>> >> > problems[1] = dtabProblems.Rows[i]["Category"].ToString();
>> >> > listView1.Items.Add(new ListViewItem(problems));
>> >> > }
>> >> >
>> >> > }
>> >> >
>> >> > The LoadProblemTitles returns a DataTable with the corresponding
>> >> > titles.
>> >> > The
>> >> > type of dtabProblems is DataTable. The data of the DataTable should
>> >> > then
>> >> > be
>> >> > displayed with the for-sequence in the listView1.
>> >> >
>> >> > Anybody an idea why a NullReferenceException occur, when I add the
>> >> > listView1.Items.Clear call to the method??:(
>> >> >
>> >> > thx
>> >> >
>> >> > robert
>> >>
>> >>
>> >>
>>
>>
>>



Re: ListView.Items.Clear?? by robert

robert
Mon Jan 03 03:31:01 CST 2005

Hello,

Thank you Daniel Moth, this caused the error! One last problem occured in my
ListView control. As said this code is the following in the
SelectedIndexChanged event:

private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (listView1.SelectedIndices.Count == 0)
{
return;
}
LoadOneProblem((string)dtabProblems.Rows[listView1.SelectedIndices[0]][0]);
title = (string)dtabProblems.Rows[listView1.SelectedIndices[0]][0];

if(Global.searchSettings == null)
{
Global.searchSettings = new SearchSettings();
Global.searchSettings.Show();
}
else
{
Global.searchSettings.LoadProblemDetails();
Global.searchSettings.Show();
}

I have mentioned in a previous posting of this thread that after clicking on
a title in the listView a new form with the details is displayed. The problem
is every time I go to the form where the ListView is placed only the second
selected title leads the user to the details form. Means when I go on the
form with the listView and click the first time on a title nothing happens,
but when I click on another title the details form with the details is
displayed.
Do you have any idea why always the second time I choose a title leads me to
the details form? :(

robert

}

"Daniel Moth" wrote:

> So what happens if you insert the following at the top of
> listView1_SelectedIndexChanged:
> if (listView.SelectedIndices.Count == 0){
> return;
> }
>
> Cheers
> Daniel
> --
> http://www.danielmoth.com/Blog/
>
>
> "robert" <robert@discussions.microsoft.com> wrote in message
> news:BD5AB19F-89D0-457E-B061-366507720189@microsoft.com...
> > Hello,
> >
> > Sorry for the effort, if the following information does not help, I would
> > develop a little sample with the corresponding code. The myColumnHeader
> > works, because I also use it on another form. I think I have this from a
> > code
> > sample of Chris Tacke. The classes for the column header are placed in the
> > same file as the form. I have a SelectedIndex Change event with the
> > following
> > code:
> >
> > private void listView1_SelectedIndexChanged(object sender,
> > System.EventArgs e)
> > {
> > LoadOneProblem((string)dtabProblems.Rows[listView1.SelectedIndices[0]][0]);
> > title =
> > (string)dtabProblems.Rows[listView1.SelectedIndices[0]][0];
> >
> > }
> >
> > I extract the value of clicked line in the ListView (of the first column)
> > because then a next form with details should be displayed automatically
> > after
> > the user clicks on on title of the listview. Could be the extracting after
> > the indices the problem for the null reference exception? - But I do not
> > know
> > how I could realize the view of the details of the selected title in
> > another
> > way? - I do not want to realize it with a extra button.
> >
> > robert
> >
> >
> > "Daniel Moth" wrote:
> >
> >> Robert, it is essential for your own benefit and when asking help from
> >> others to be able to provide a small reproducible sample. By isolating
> >> the
> >> problem you can zoom in on the solution. For example, where is this
> >> myColumnHeader class?
> >>
> >> Anyway, we can continue the question game. Have you got any event
> >> handlers
> >> (e.g. SelctedIndexChanged) attached to the listview? These will likely
> >> fire
> >> when you clear the listview; stick a breakpoint in there or even better
> >> wrap
> >> the method with a try..catch to see if that is the case.
> >>
> >> Cheers
> >> Daniel
> >> --
> >> http://www.danielmoth.com/Blog/
> >>
> >>
> >> "robert" <robert@discussions.microsoft.com> wrote in message
> >> news:6959B290-7292-4C9B-AAD1-826F2FD25747@microsoft.com...
> >> > Hello,
> >> >
> >> > It is a little problem to post it in a sample because this method is
> >> > part
> >> > of
> >> > a whole application.
> >> > I initialize the two columns in the fields part before the constructor
> >> > of
> >> > the form:
> >> >
> >> > private myColumnHeader Title = new myColumnHeader("Title", 142,
> >> > HorizontalAlignment.Center,true);
> >> > private myColumnHeader category = new myColumnHeader("Category", 68,
> >> > HorizontalAlignment.Left, true);
> >> >
> >> > in the constructor of the form I add the columns to the listView:
> >> >
> >> > listView1.Columns.Add(Title);
> >> > listView1.Columns.Add(category);
> >> > listView1.View = System.Windows.Forms.View.Details;
> >> > listView1.FullRowSelect = true;
> >> >
> >> > this lines are placed after the call of the InitializeComponent method.
> >> > The
> >> > previous posted method is called also in the constructor of the form
> >> > but
> >> > after the above lines.
> >> >
> >> > thats all. the LoadProblemTitles is placed in the data.cs file and
> >> > retrieves
> >> > the titles and the corresponding category and save these data in the
> >> > dtabProblems dataTable.
> >> >
> >> > Does this help you? - I did not find the error..:( I must be this code
> >> > line
> >> > because when I omit this line the code works without problems but the
> >> > listView is not cleared after every loading. It must also be this line
> >> > because I placed a MessageBox after the clear statement and the
> >> > MessageBox
> >> > does not appear when I execute the code.
> >> >
> >> > Have you got any idea?
> >> >
> >> > robert
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > "Daniel Moth" wrote:
> >> >
> >> >> Where are you calling the method from? Has the listview been created
> >> >> (has
> >> >> it
> >> >> got columns etc setup)? Have you tried adding a try..catch around the
> >> >> listView1.Items.Clear() to make sure it is that line that throws?
> >> >>
> >> >> If you post a small sample (not just a method) that demonstrates the
> >> >> problem
> >> >> I can try to debug it (e.g. calling clear from a button click with no
> >> >> other
> >> >> statements in it). A simple repro I have works fine in the PPC
> >> >> emulator
> >> >> (what are you testing this on?).
> >> >>
> >> >> Cheers
> >> >> Daniel
> >> >> --
> >> >> http://www.danielmoth.com/Blog/
> >> >>
> >> >>
> >> >> "robert" <robert@discussions.microsoft.com> wrote in message
> >> >> news:83B98049-B807-49DA-9F08-DC2FE7066BC8@microsoft.com...
> >> >> > Hello,
> >> >> >
> >> >> > The following clear call in the LoadTitle method produces the
> >> >> > NullReferenceException:
> >> >> >
> >> >> > public void LoadTitle()
> >> >> > {
> >> >> >
> >> >> > listView1.Items.Clear();
> >> >> >
> >> >> > ArrayList arrayList = new ArrayList();
> >> >> > dtabProblems = database.LoadProblemTitles(new
> >> >> > Guid(Replication.getJobId()));
> >> >> > for(int i = 0; i < dtabProblems.Rows.Count; i++)
> >> >> > {
> >> >> > string[] problems = new string[2];
> >> >> > problems[0] = dtabProblems.Rows[i]["Titel"].ToString();
> >> >> > problems[1] = dtabProblems.Rows[i]["Category"].ToString();
> >> >> > listView1.Items.Add(new ListViewItem(problems));
> >> >> > }
> >> >> >
> >> >> > }
> >> >> >
> >> >> > The LoadProblemTitles returns a DataTable with the corresponding
> >> >> > titles.
> >> >> > The
> >> >> > type of dtabProblems is DataTable. The data of the DataTable should
> >> >> > then
> >> >> > be
> >> >> > displayed with the for-sequence in the listView1.
> >> >> >
> >> >> > Anybody an idea why a NullReferenceException occur, when I add the
> >> >> > listView1.Items.Clear call to the method??:(
> >> >> >
> >> >> > thx
> >> >> >
> >> >> > robert
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>

Re: ListView.Items.Clear?? by Daniel

Daniel
Mon Jan 03 08:51:46 CST 2005

Glad it fixed it for you. Sorry I don't quite follow your new problem.

Can you post a small sample that reproduces the problem? And to get the
attention of others too, please start a different thread.

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"robert" <robert@discussions.microsoft.com> wrote in message
news:F1377DB5-E33D-4DAC-9677-5ADD44E81015@microsoft.com...
> Hello,
>
> Thank you Daniel Moth, this caused the error! One last problem occured in
> my
> ListView control. As said this code is the following in the
> SelectedIndexChanged event:
>
> private void listView1_SelectedIndexChanged(object sender,
> System.EventArgs e)
> {
> if (listView1.SelectedIndices.Count == 0)
> {
> return;
> }
> LoadOneProblem((string)dtabProblems.Rows[listView1.SelectedIndices[0]][0]);
> title = (string)dtabProblems.Rows[listView1.SelectedIndices[0]][0];
>
> if(Global.searchSettings == null)
> {
> Global.searchSettings = new SearchSettings();
> Global.searchSettings.Show();
> }
> else
> {
> Global.searchSettings.LoadProblemDetails();
> Global.searchSettings.Show();
> }
>
> I have mentioned in a previous posting of this thread that after clicking
> on
> a title in the listView a new form with the details is displayed. The
> problem
> is every time I go to the form where the ListView is placed only the
> second
> selected title leads the user to the details form. Means when I go on the
> form with the listView and click the first time on a title nothing
> happens,
> but when I click on another title the details form with the details is
> displayed.
> Do you have any idea why always the second time I choose a title leads me
> to
> the details form? :(
>
> robert
>
> }
>
> "Daniel Moth" wrote:
>
>> So what happens if you insert the following at the top of
>> listView1_SelectedIndexChanged:
>> if (listView.SelectedIndices.Count == 0){
>> return;
>> }
>>
>> Cheers
>> Daniel
>> --
>> http://www.danielmoth.com/Blog/
>>
>>
>> "robert" <robert@discussions.microsoft.com> wrote in message
>> news:BD5AB19F-89D0-457E-B061-366507720189@microsoft.com...
>> > Hello,
>> >
>> > Sorry for the effort, if the following information does not help, I
>> > would
>> > develop a little sample with the corresponding code. The myColumnHeader
>> > works, because I also use it on another form. I think I have this from
>> > a
>> > code
>> > sample of Chris Tacke. The classes for the column header are placed in
>> > the
>> > same file as the form. I have a SelectedIndex Change event with the
>> > following
>> > code:
>> >
>> > private void listView1_SelectedIndexChanged(object sender,
>> > System.EventArgs e)
>> > {
>> > LoadOneProblem((string)dtabProblems.Rows[listView1.SelectedIndices[0]][0]);
>> > title =
>> > (string)dtabProblems.Rows[listView1.SelectedIndices[0]][0];
>> >
>> > }
>> >
>> > I extract the value of clicked line in the ListView (of the first
>> > column)
>> > because then a next form with details should be displayed automatically
>> > after
>> > the user clicks on on title of the listview. Could be the extracting
>> > after
>> > the indices the problem for the null reference exception? - But I do
>> > not
>> > know
>> > how I could realize the view of the details of the selected title in
>> > another
>> > way? - I do not want to realize it with a extra button.
>> >
>> > robert
>> >
>> >
>> > "Daniel Moth" wrote:
>> >
>> >> Robert, it is essential for your own benefit and when asking help from
>> >> others to be able to provide a small reproducible sample. By isolating
>> >> the
>> >> problem you can zoom in on the solution. For example, where is this
>> >> myColumnHeader class?
>> >>
>> >> Anyway, we can continue the question game. Have you got any event
>> >> handlers
>> >> (e.g. SelctedIndexChanged) attached to the listview? These will likely
>> >> fire
>> >> when you clear the listview; stick a breakpoint in there or even
>> >> better
>> >> wrap
>> >> the method with a try..catch to see if that is the case.
>> >>
>> >> Cheers
>> >> Daniel
>> >> --
>> >> http://www.danielmoth.com/Blog/
>> >>
>> >>
>> >> "robert" <robert@discussions.microsoft.com> wrote in message
>> >> news:6959B290-7292-4C9B-AAD1-826F2FD25747@microsoft.com...
>> >> > Hello,
>> >> >
>> >> > It is a little problem to post it in a sample because this method is
>> >> > part
>> >> > of
>> >> > a whole application.
>> >> > I initialize the two columns in the fields part before the
>> >> > constructor
>> >> > of
>> >> > the form:
>> >> >
>> >> > private myColumnHeader Title = new myColumnHeader("Title", 142,
>> >> > HorizontalAlignment.Center,true);
>> >> > private myColumnHeader category = new myColumnHeader("Category", 68,
>> >> > HorizontalAlignment.Left, true);
>> >> >
>> >> > in the constructor of the form I add the columns to the listView:
>> >> >
>> >> > listView1.Columns.Add(Title);
>> >> > listView1.Columns.Add(category);
>> >> > listView1.View = System.Windows.Forms.View.Details;
>> >> > listView1.FullRowSelect = true;
>> >> >
>> >> > this lines are placed after the call of the InitializeComponent
>> >> > method.
>> >> > The
>> >> > previous posted method is called also in the constructor of the form
>> >> > but
>> >> > after the above lines.
>> >> >
>> >> > thats all. the LoadProblemTitles is placed in the data.cs file and
>> >> > retrieves
>> >> > the titles and the corresponding category and save these data in the
>> >> > dtabProblems dataTable.
>> >> >
>> >> > Does this help you? - I did not find the error..:( I must be this
>> >> > code
>> >> > line
>> >> > because when I omit this line the code works without problems but
>> >> > the
>> >> > listView is not cleared after every loading. It must also be this
>> >> > line
>> >> > because I placed a MessageBox after the clear statement and the
>> >> > MessageBox
>> >> > does not appear when I execute the code.
>> >> >
>> >> > Have you got any idea?
>> >> >
>> >> > robert
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > "Daniel Moth" wrote:
>> >> >
>> >> >> Where are you calling the method from? Has the listview been
>> >> >> created
>> >> >> (has
>> >> >> it
>> >> >> got columns etc setup)? Have you tried adding a try..catch around
>> >> >> the
>> >> >> listView1.Items.Clear() to make sure it is that line that throws?
>> >> >>
>> >> >> If you post a small sample (not just a method) that demonstrates
>> >> >> the
>> >> >> problem
>> >> >> I can try to debug it (e.g. calling clear from a button click with
>> >> >> no
>> >> >> other
>> >> >> statements in it). A simple repro I have works fine in the PPC
>> >> >> emulator
>> >> >> (what are you testing this on?).
>> >> >>
>> >> >> Cheers
>> >> >> Daniel
>> >> >> --
>> >> >> http://www.danielmoth.com/Blog/
>> >> >>
>> >> >>
>> >> >> "robert" <robert@discussions.microsoft.com> wrote in message
>> >> >> news:83B98049-B807-49DA-9F08-DC2FE7066BC8@microsoft.com...
>> >> >> > Hello,
>> >> >> >
>> >> >> > The following clear call in the LoadTitle method produces the
>> >> >> > NullReferenceException:
>> >> >> >
>> >> >> > public void LoadTitle()
>> >> >> > {
>> >> >> >
>> >> >> > listView1.Items.Clear();
>> >> >> >
>> >> >> > ArrayList arrayList = new ArrayList();
>> >> >> > dtabProblems = database.LoadProblemTitles(new
>> >> >> > Guid(Replication.getJobId()));
>> >> >> > for(int i = 0; i < dtabProblems.Rows.Count; i++)
>> >> >> > {
>> >> >> > string[] problems = new string[2];
>> >> >> > problems[0] = dtabProblems.Rows[i]["Titel"].ToString();
>> >> >> > problems[1] = dtabProblems.Rows[i]["Category"].ToString();
>> >> >> > listView1.Items.Add(new ListViewItem(problems));
>> >> >> > }
>> >> >> >
>> >> >> > }
>> >> >> >
>> >> >> > The LoadProblemTitles returns a DataTable with the corresponding
>> >> >> > titles.
>> >> >> > The
>> >> >> > type of dtabProblems is DataTable. The data of the DataTable
>> >> >> > should
>> >> >> > then
>> >> >> > be
>> >> >> > displayed with the for-sequence in the listView1.
>> >> >> >
>> >> >> > Anybody an idea why a NullReferenceException occur, when I add
>> >> >> > the
>> >> >> > listView1.Items.Clear call to the method??:(
>> >> >> >
>> >> >> > thx
>> >> >> >
>> >> >> > robert
>> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>
>>
>>
>>



Re: ListView.Items.Clear?? by robert

robert
Mon Jan 03 14:27:02 CST 2005

Hello,

It is the same problem as with the other one. The whole application is based
on the SQL Server CE database and it is very difficult for me to transport
the problem code to a code sample that work independently. I thought it is a
common problem that it is not possible to select the first time a line in a
ListView and redirected it immediately to another form. The strange thing is
when I add a code for a messageBox between the saving of the title of the
corresponding line in the ListView and the forwarding to the next form then
the code work correctly. It is very strange for me. I tried to develop an own
code sample which represents the same problem.

robert

"Daniel Moth" wrote:

> Glad it fixed it for you. Sorry I don't quite follow your new problem.
>
> Can you post a small sample that reproduces the problem? And to get the
> attention of others too, please start a different thread.
>
> Cheers
> Daniel
> --
> http://www.danielmoth.com/Blog/
>
>
> "robert" <robert@discussions.microsoft.com> wrote in message
> news:F1377DB5-E33D-4DAC-9677-5ADD44E81015@microsoft.com...
> > Hello,
> >
> > Thank you Daniel Moth, this caused the error! One last problem occured in
> > my
> > ListView control. As said this code is the following in the
> > SelectedIndexChanged event:
> >
> > private void listView1_SelectedIndexChanged(object sender,
> > System.EventArgs e)
> > {
> > if (listView1.SelectedIndices.Count == 0)
> > {
> > return;
> > }
> > LoadOneProblem((string)dtabProblems.Rows[listView1.SelectedIndices[0]][0]);
> > title = (string)dtabProblems.Rows[listView1.SelectedIndices[0]][0];
> >
> > if(Global.searchSettings == null)
> > {
> > Global.searchSettings = new SearchSettings();
> > Global.searchSettings.Show();
> > }
> > else
> > {
> > Global.searchSettings.LoadProblemDetails();
> > Global.searchSettings.Show();
> > }
> >
> > I have mentioned in a previous posting of this thread that after clicking
> > on
> > a title in the listView a new form with the details is displayed. The
> > problem
> > is every time I go to the form where the ListView is placed only the
> > second
> > selected title leads the user to the details form. Means when I go on the
> > form with the listView and click the first time on a title nothing
> > happens,
> > but when I click on another title the details form with the details is
> > displayed.
> > Do you have any idea why always the second time I choose a title leads me
> > to
> > the details form? :(
> >
> > robert
> >
> > }
> >
> > "Daniel Moth" wrote:
> >
> >> So what happens if you insert the following at the top of
> >> listView1_SelectedIndexChanged:
> >> if (listView.SelectedIndices.Count == 0){
> >> return;
> >> }
> >>
> >> Cheers
> >> Daniel
> >> --
> >> http://www.danielmoth.com/Blog/
> >>
> >>
> >> "robert" <robert@discussions.microsoft.com> wrote in message
> >> news:BD5AB19F-89D0-457E-B061-366507720189@microsoft.com...
> >> > Hello,
> >> >
> >> > Sorry for the effort, if the following information does not help, I
> >> > would
> >> > develop a little sample with the corresponding code. The myColumnHeader
> >> > works, because I also use it on another form. I think I have this from
> >> > a
> >> > code
> >> > sample of Chris Tacke. The classes for the column header are placed in
> >> > the
> >> > same file as the form. I have a SelectedIndex Change event with the
> >> > following
> >> > code:
> >> >
> >> > private void listView1_SelectedIndexChanged(object sender,
> >> > System.EventArgs e)
> >> > {
> >> > LoadOneProblem((string)dtabProblems.Rows[listView1.SelectedIndices[0]][0]);
> >> > title =
> >> > (string)dtabProblems.Rows[listView1.SelectedIndices[0]][0];
> >> >
> >> > }
> >> >
> >> > I extract the value of clicked line in the ListView (of the first
> >> > column)
> >> > because then a next form with details should be displayed automatically
> >> > after
> >> > the user clicks on on title of the listview. Could be the extracting
> >> > after
> >> > the indices the problem for the null reference exception? - But I do
> >> > not
> >> > know
> >> > how I could realize the view of the details of the selected title in
> >> > another
> >> > way? - I do not want to realize it with a extra button.
> >> >
> >> > robert
> >> >
> >> >
> >> > "Daniel Moth" wrote:
> >> >
> >> >> Robert, it is essential for your own benefit and when asking help from
> >> >> others to be able to provide a small reproducible sample. By isolating
> >> >> the
> >> >> problem you can zoom in on the solution. For example, where is this
> >> >> myColumnHeader class?
> >> >>
> >> >> Anyway, we can continue the question game. Have you got any event
> >> >> handlers
> >> >> (e.g. SelctedIndexChanged) attached to the listview? These will likely
> >> >> fire
> >> >> when you clear the listview; stick a breakpoint in there or even
> >> >> better
> >> >> wrap
> >> >> the method with a try..catch to see if that is the case.
> >> >>
> >> >> Cheers
> >> >> Daniel
> >> >> --
> >> >> http://www.danielmoth.com/Blog/
> >> >>
> >> >>
> >> >> "robert" <robert@discussions.microsoft.com> wrote in message
> >> >> news:6959B290-7292-4C9B-AAD1-826F2FD25747@microsoft.com...
> >> >> > Hello,
> >> >> >
> >> >> > It is a little problem to post it in a sample because this method is
> >> >> > part
> >> >> > of
> >> >> > a whole application.
> >> >> > I initialize the two columns in the fields part before the
> >> >> > constructor
> >> >> > of
> >> >> > the form:
> >> >> >
> >> >> > private myColumnHeader Title = new myColumnHeader("Title", 142,
> >> >> > HorizontalAlignment.Center,true);
> >> >> > private myColumnHeader category = new myColumnHeader("Category", 68,
> >> >> > HorizontalAlignment.Left, true);
> >> >> >
> >> >> > in the constructor of the form I add the columns to the listView:
> >> >> >
> >> >> > listView1.Columns.Add(Title);
> >> >> > listView1.Columns.Add(category);
> >> >> > listView1.View = System.Windows.Forms.View.Details;
> >> >> > listView1.FullRowSelect = true;
> >> >> >
> >> >> > this lines are placed after the call of the InitializeComponent
> >> >> > method.
> >> >> > The
> >> >> > previous posted method is called also in the constructor of the form
> >> >> > but
> >> >> > after the above lines.
> >> >> >
> >> >> > thats all. the LoadProblemTitles is placed in the data.cs file and
> >> >> > retrieves
> >> >> > the titles and the corresponding category and save these data in the
> >> >> > dtabProblems dataTable.
> >> >> >
> >> >> > Does this help you? - I did not find the error..:( I must be this
> >> >> > code
> >> >> > line
> >> >> > because when I omit this line the code works without problems but
> >> >> > the
> >> >> > listView is not cleared after every loading. It must also be this
> >> >> > line
> >> >> > because I placed a MessageBox after the clear statement and the
> >> >> > MessageBox
> >> >> > does not appear when I execute the code.
> >> >> >
> >> >> > Have you got any idea?
> >> >> >
> >> >> > robert
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> > "Daniel Moth" wrote:
> >> >> >
> >> >> >> Where are you calling the method from? Has the listview been
> >> >> >> created
> >> >> >> (has
> >> >> >> it
> >> >> >> got columns etc setup)? Have you tried adding a try..catch around
> >> >> >> the
> >> >> >> listView1.Items.Clear() to make sure it is that line that throws?
> >> >> >>
> >> >> >> If you post a small sample (not just a method) that demonstrates
> >> >> >> the
> >> >> >> problem
> >> >> >> I can try to debug it (e.g. calling clear from a button click with
> >> >> >> no
> >> >> >> other
> >> >> >> statements in it). A simple repro I have works fine in the PPC
> >> >> >> emulator
> >> >> >> (what are you testing this on?).
> >> >> >>
> >> >> >> Cheers
> >> >> >> Daniel
> >> >> >> --
> >> >> >> http://www.danielmoth.com/Blog/
> >> >> >>
> >> >> >>
> >> >> >> "robert" <robert@discussions.microsoft.com> wrote in message
> >> >> >> news:83B98049-B807-49DA-9F08-DC2FE7066BC8@microsoft.com...
> >> >> >> > Hello,
> >> >> >> >
> >> >> >> > The following clear call in the LoadTitle method produces the
> >> >> >> > NullReferenceException:
> >> >> >> >
> >> >> >> > public void LoadTitle()
> >> >> >> > {
> >> >> >> >
> >> >> >> > listView1.Items.Clear();
> >> >> >> >
> >> >> >> > ArrayList arrayList = new ArrayList();
> >> >> >> > dtabProblems = database.LoadProblemTitles(new
> >> >> >> > Guid(Replication.getJobId()));
> >> >> >> > for(int i = 0; i < dtabProblems.Rows.Count; i++)
> >> >> >> > {
> >> >> >> > string[] problems = new string[2];
> >> >> >> > problems[0] = dtabProblems.Rows[i]["Titel"].ToString();
> >> >> >> > problems[1] = dtabProblems.Rows[i]["Category"].ToString();
> >> >> >> > listView1.Items.Add(new ListViewItem(problems));
> >> >> >> > }
> >> >> >> >
> >> >> >> > }
> >> >> >> >
> >> >> >> > The LoadProblemTitles returns a DataTable with the corresponding
> >> >> >> > titles.
> >> >> >> > The
> >> >> >> > type of dtabProblems is DataTable. The data of the DataTable
> >> >> >> > should
> >> >> >> > then
> >> >> >> > be
> >> >> >> > displayed with the for-sequence in the listView1.
> >> >> >> >
> >> >> >> > Anybody an idea why a NullReferenceException occur, when I add
> >> >> >> > the
> >> >> >> > listView1.Items.Clear call to the method??:(
> >> >> >> >
> >> >> >> > thx
> >> >> >> >
> >> >> >> > robert
> >> >> >>
> >> >> >>
> >> >> >>
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>

Re: ListView.Items.Clear?? by Daniel

Daniel
Mon Jan 03 15:02:46 CST 2005

It is not a common problem hence the need to see your code. If I were
showing a form from a listview I would do it in the ItemActivate event.
Check out the Activation property.

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"robert" <robert@discussions.microsoft.com> wrote in message
news:2CC5FB4B-5F0D-4E6A-9073-E0ED0589D17F@microsoft.com...
> Hello,
>
> It is the same problem as with the other one. The whole application is
> based
> on the SQL Server CE database and it is very difficult for me to transport
> the problem code to a code sample that work independently. I thought it is
> a
> common problem that it is not possible to select the first time a line in
> a
> ListView and redirected it immediately to another form. The strange thing
> is
> when I add a code for a messageBox between the saving of the title of the
> corresponding line in the ListView and the forwarding to the next form
> then
> the code work correctly. It is very strange for me. I tried to develop an
> own
> code sample which represents the same problem.
>
> robert
>
> "Daniel Moth" wrote:
>
>> Glad it fixed it for you. Sorry I don't quite follow your new problem.
>>
>> Can you post a small sample that reproduces the problem? And to get the
>> attention of others too, please start a different thread.
>>
>> Cheers
>> Daniel
>> --
>> http://www.danielmoth.com/Blog/
>>
>>
>> "robert" <robert@discussions.microsoft.com> wrote in message
>> news:F1377DB5-E33D-4DAC-9677-5ADD44E81015@microsoft.com...
>> > Hello,
>> >
>> > Thank you Daniel Moth, this caused the error! One last problem occured
>> > in
>> > my
>> > ListView control. As said this code is the following in the
>> > SelectedIndexChanged event:
>> >
>> > private void listView1_SelectedIndexChanged(object sender,
>> > System.EventArgs e)
>> > {
>> > if (listView1.SelectedIndices.Count == 0)
>> > {
>> > return;
>> > }
>> > LoadOneProblem((string)dtabProblems.Rows[listView1.SelectedIndices[0]][0]);
>> > title = (string)dtabProblems.Rows[listView1.SelectedIndices[0]][0];
>> >
>> > if(Global.searchSettings == null)
>> > {
>> > Global.searchSettings = new SearchSettings();
>> > Global.searchSettings.Show();
>> > }
>> > else
>> > {
>> > Global.searchSettings.LoadProblemDetails();
>> > Global.searchSettings.Show();
>> > }
>> >
>> > I have mentioned in a previous posting of this thread that after
>> > clicking
>> > on
>> > a title in the listView a new form with the details is displayed. The
>> > problem
>> > is every time I go to the form where the ListView is placed only the
>> > second
>> > selected title leads the user to the details form. Means when I go on
>> > the
>> > form with the listView and click the first time on a title nothing
>> > happens,
>> > but when I click on another title the details form with the details is
>> > displayed.
>> > Do you have any idea why always the second time I choose a title leads
>> > me
>> > to
>> > the details form? :(
>> >
>> > robert
>> >
>> > }
>> >
>> > "Daniel Moth" wrote:
>> >
>> >> So what happens if you insert the following at the top of
>> >> listView1_SelectedIndexChanged:
>> >> if (listView.SelectedIndices.Count == 0){
>> >> return;
>> >> }
>> >>
>> >> Cheers
>> >> Daniel
>> >> --
>> >> http://www.danielmoth.com/Blog/
>> >>
>> >>
>> >> "robert" <robert@discussions.microsoft.com> wrote in message
>> >> news:BD5AB19F