Solved

ListView not repainting

Posted on 2004-10-20
6
445 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
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now