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
> >> >> >>
> >> >> >>
> >> >> >>
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>