Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ListView not repainting

Posted on 2004-10-20
6
Medium Priority
?
460 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 6

Accepted Solution

by:
viola123 earned 375 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

609 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