Solved

ListView not repainting

Posted on 2004-10-20
6
451 Views
Last Modified: 2010-07-27
I have a form that contains a ListView set to Detail view type. And when the form loads it runs the following code:

OdbcConnection conn = new OdbcConnection ("DSN=Data");
                        conn.Open();
                        OdbcCommand cmd = new OdbcCommand("SELECT Field1, Field2 FROM Table1",conn);

                        OdbcDataReader data= cmd.ExecuteReader();
                        lstViewUsers.Clear();
                   
                        while(data.Read()){
                              ListViewItem lvi=lstViewUsers.Items.Add(data.GetString(0));
                                OdbcConnection conn2 = new OdbcConnection("DSN=Data");
                                conn2.Open();
                                OdbcCommand cmd2=new OdbcCommand("SELECT Field1, Field2 Field3 FROM Table2 WHERE Field1 = '"+data.GetString(0)+"';",conn2);                                OdbcDataReader data2 = cmd2.ExecuteReader();

                                if(data2.HasRows){
                                      data2.Read();
                                      lvi.SubItems.Add(data2.GetString(0));
                                      lvi.SubItems.Add(data2.GetDate(1).ToString("g"));
                                      lvi.SubItems.Add(data2.GetDate(2).ToString("g"));
                                }
                                else {
                                      lvi.SubItems.Add("");
                                        lvi.SubItems.Add("");
                                        lvi.SubItems.Add("");
                                }
                                data2.Close();
                                conn2.Close();
                                if(data.GetBoolean(1))
                                      lvi.SubItems.Add("Yes");
                                else
                                      lvi.SubItems.Add("No");
                  }

                        data.Close();
                        conn.Close();

And as a result somehow the ListView Does not repaint itself (it also happened Else where in the program but the solution should be the same.
0
Comment
Question by:gilllyo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 15

Expert Comment

by:SRigney
ID: 12357370
If you minimize your app, and then restore it, does the listview repaint itself correctly?
0
 
LVL 3

Expert Comment

by:aacool
ID: 12358227
Try putting in a call to listViewUsers.Update(); - ideally, start your function with
listViewUsers.BeginUpdate();  and end with listViewUsers.EndUpdate();

See if this works
0
 
LVL 15

Expert Comment

by:SRigney
ID: 12359091
listViewUsers.Refresh() may work as well.
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 6

Accepted Solution

by:
viola123 earned 125 total points
ID: 12366125
using
lstViewUsers.Items.Clear();
lstViewUsers.Columns.Clear();

before you send any items to listview.

i suggest you creat a method that used to display dataset in listview and then call this method whenever you need.
0
 

Author Comment

by:gilllyo
ID: 12366805
When I minimiz then come back all the headings are greyed out and there are no items in the list.

I put the headers in during design time so I don't want to clear the Headers

If you noticed I had the code:

lstViewUsers.Clear();

I changed this to:

lstViewUsers.Items.Clear();

And it displays what it should.

Thanks
0
 
LVL 6

Expert Comment

by:viola123
ID: 12367105
i am glad it helps

viola
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question