473,794 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c# - ListView Not always displaying Images (tile view)

77 New Member
Hi, i am trying to use a list view to display a list of passed and failed items but the images are not always displaying. Sometimes the images will display fine and others they just will not appear.

I've created an ImageList and added the images to it by:
imageList1.Imag es.Add(Bitmap.F romFile(Applica tion.StartupPat h + "\\Images\\imag e.gif"));

I set the small and large Image list properties on the ListView to the newly created image list. I tried swapping these around i.e. only using smallimagelist etc. but still have the same issue. I can not seem to figure out what i am doing wrong. I've tried this both in release and debug mode(however, I did have some issues in release mode which I have now fixed).

Anyone be able to help me with this issue?

Thanks in advance,
Piercy

edit: Heres and image to see what i mean.. These were taken within 5 minutes of each other with no code changes between. just a note, the names are all demo data so dont worry about that.

Apr 8 '08 #1
3 5765
piercy
77 New Member
B U M P

Im still extremly stuck on this dont have a clue what the problem is.

I tried this: (as suggested by Francisco25)
Expand|Select|Wrap|Line Numbers
  1. LockWindowUpdate(this.Handle); //Lock the windows main client for refreshing
  2.  
  3. imageList1.Images.Add(Bitmap.FromFile(Application.StartupPath + "\\Images\\image.gif"));
  4.  
  5. LockWindowUpdate(IntPtr.Zero); //Unlock all the locked windows
  6.  
  7.  
  8. Application.DoEvents(); //Refresh all the events in the queu
  9.  
But it didnt work.

im not sure what other code i can show you as all im really doing is populating the box from a database and displaying some text on the page. Heres the part where i add to the list view. It gets some information from a already populated datagrid then select the correct message and receipiants from the database and populate accordingly. (and yes i know receipiants is not spelled like receipitants but i dont want to have to change the database...) also, the refreshes were to try help fix the problem. Ill remove them eventually..:

Expand|Select|Wrap|Line Numbers
  1. private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
  2.         {
  3.  
  4.             System.Drawing.Point pt = dataGrid1.PointToClient(Cursor.Position);
  5.             listView1.Items.Clear();
  6.             dg1val = dataGrid1[dataGrid1.CurrentCell.RowNumber, 0].ToString();
  7.             dg1val = dg1val.Replace(":","");
  8.             dg1val = dg1val.Replace("/","");
  9.             dg1val = dg1val.Replace(" ","");
  10.             this.sqlSelectCommand2.CommandText = "SELECT PupilID, Receipitant,ErrorID, Display, errormess FROM Receipitants INNER JOIN ErrorID ON Receipitants.ErrorID = ErrorID.ID WHERE (Receipitants.MsgID =" + this.dg1val.ToString() + ") ORDER BY Receipitants.ErrorID";
  11.  
  12.  
  13.             try
  14.             {
  15.  
  16.                 ds1.Tables["Receipitants"].Clear();
  17.             }
  18.             catch { }
  19.             try
  20.             {
  21.                 this.sqlDataAdapter2.Fill(ds1, "Receipitants");
  22.             }
  23.             catch (System.Exception ex)
  24.             {
  25.                 MessageBox.Show(ex.Message.ToString());
  26.             }
  27.  
  28.  
  29.             DataTable temp = this.ds.Tables["Message"];
  30.             foreach (DataRow row in ds1.Tables["Receipitants"].Rows)
  31.             {
  32.                 if (row.ItemArray[1].ToString() != null)
  33.                 {
  34.                     if (row.ItemArray[1].ToString().Length > 0)
  35.                     {
  36.                         ListViewItem lvi = new ListViewItem(new string[] { row.ItemArray[3].ToString() + " (" + row.ItemArray[1].ToString() + ")"},0);
  37.                         lvi.ToolTipText = row.ItemArray[4].ToString();
  38.                         listView1.Items.Add(lvi);
  39.  
  40.                     }
  41.                     else
  42.                     {
  43.                         ListViewItem lvi = new ListViewItem(row.ItemArray[3].ToString());
  44.                         lvi.ToolTipText = row.ItemArray[4].ToString();
  45.                         lvi.ImageIndex = 1;
  46.                         listView1.Items.Add(lvi);
  47.                     }
  48.                 }
  49.                 else
  50.                 {
  51.                     ListViewItem lvi = new ListViewItem(row.ItemArray[3].ToString());
  52.                     lvi.ToolTipText = row.ItemArray[4].ToString();
  53.                     lvi.ImageIndex = 1;
  54.                     listView1.Items.Add(lvi);
  55.                 }
  56.             }
  57.             string command = "SELECT Subject,Body FROM [Message] WHERE MsgID=@id";
  58.             string message = null;
  59.             string subject = null;
  60.             try
  61.             {
  62.                 conn.Open();
  63.                 SqlCommand cmd = new SqlCommand(command, conn);
  64.                 cmd.Parameters.Add("@id", SqlDbType.BigInt).Value = dg1val.ToString();
  65.                 SqlDataReader myReader = cmd.ExecuteReader();
  66.                 while (myReader.Read())
  67.                 {
  68.                     subject = myReader[0].ToString();
  69.                     message = myReader[1].ToString();
  70.                 }
  71.  
  72.             }
  73.             catch (System.Exception ex)
  74.             {
  75.                 MessageBox.Show(this, "Database Error: " + ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  76.             }
  77.             finally
  78.             {
  79.                 conn.Close();
  80.             }
  81.             this.richTextBox1.Text = message;
  82.             this.richTextBox2.Text = subject;
  83.             listView1.Refresh();
  84.             Size temp1 = listView1.TileSize;
  85.             temp1.Width = ((listView1.Size.Width - System.Windows.Forms.SystemInformation.VerticalScrollBarWidth)-(3*16)) / 3;
  86.             listView1.TileSize = temp1;
  87.             listView1.Refresh();
  88.  
  89.             this.Refresh();
  90.         }
  91.  
Thanks again,
Piercy
Apr 9 '08 #2
piercy
77 New Member
Ok, I think i've solved it... Found this post:
http://rikkus.info/workaround-to-lis...ng-images.html
And after moving enablevisualsty le very slightly it seems to be working. Im not definate this is the solution because my problems intermitant but ive tested it a good 30 times now and it seems fine. If i have any more problems related to this ill post back. Thought id post this here so if anyones searching for the solution they find this.

Thanks,
Piercy
Apr 10 '08 #3
manpakhong
3 New Member
I have an experience using Ajax, that I use the tab extendion. I use an image button that the name is conflict with others, but the compiler cannot detected it and the image is not displayed properly.

Regards,
Man Pak Hong
manpahong@hotma il.com


Hi, i am trying to use a list view to display a list of passed and failed items but the images are not always displaying. Sometimes the images will display fine and others they just will not appear.

I've created an ImageList and added the images to it by:
imageList1.Imag es.Add(Bitmap.F romFile(Applica tion.StartupPat h + "\\Images\\imag e.gif"));

I set the small and large Image list properties on the ListView to the newly created image list. I tried swapping these around i.e. only using smallimagelist etc. but still have the same issue. I can not seem to figure out what i am doing wrong. I've tried this both in release and debug mode(however, I did have some issues in release mode which I have now fixed).

Anyone be able to help me with this issue?

Thanks in advance,
Piercy

edit: Heres and image to see what i mean.. These were taken within 5 minutes of each other with no code changes between. just a note, the names are all demo data so dont worry about that.

Apr 10 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1920
by: tommazzo | last post by:
I'm currently writing a photo album sotware in C#. I'm using a ListView component to diaplay thumbnail previews of the photos and want to give the user the possibility to rearrange the photos via a drag&drop operation. The problem is that it only appears to be possible to rearrange items in a ListView if its view property is not set to View.LargeIcons (which is the one I need to diaplay the thumbs). If I rearrage the items without changing...
2
4737
by: Anushya devi | last post by:
Hi All I used listview and tried to update it by using Addrange. When the number of items is less, it works fine.. But I need to update nearly 200,000 items and it hangs. Also i need to add images to listview also(This is to list all the items in my inbox, and want to give the user the feel of outlook). Since it hangs for even 1000 items in the inbox, i tried to shift to virtual listview. But virtual listview
1
3451
by: newbie | last post by:
Hello, I maybe asking too much in a single posting, but here it goes: I building a windows form that mimic's the Outlook XP GUI. Its a three pane form that will allow a user to view and edit records in a database. A Treeview in the left pane, a Listview in the TopRight Pane, and a PropertyGrid in the BottomRight; The Treeview will allow the user to select an "Entity" to view, the listview will display a list of instances of
4
1591
by: | last post by:
I think .NET 1.1.4322 ListView control has some bugs .I set ListView for displaying details I set multiselect and fullrowselect to true.I set small image list.When I compile it works well.But finally I add some context mrnu to listview but after next compile ,list view doesnot draws images .If I delete and add new everything goes normal.But when I do some change on form or I change a setting of listview again it begins to undraw images.
3
6582
by: scoobydoo | last post by:
hi, I have a problem displaying icons at the right colour depthin a ListView. I've made an icon file, (using IconWorkshop 5), it has 3 icons within it. A 32x32 32bpp XP style icon, a 32x32 32bpp non-xp icon (no transparency), and a 16x16 version. I add these icons to an ImageList, which is then assigned to the LargeImageList property of the ListView.
11
375
by: Pedro Fernandes | last post by:
Hi all. I have a problem when I do interop between .NET and VB6. What happens is that the listview loses the tile view when my .NET form is under VB6. Does VB6 support this feature? Thanks.
1
4635
by: > Adrian | last post by:
I have a form with two list views. In one list view the tile size is set to the default value 0,0. I have not made any changes to these values. In the other list view the tile size has values. I want to reset those values to the default values. However if I enter 0,0, those values are found unacceptable. Question: how can I reset tile size to the default values (0,0)? Thank you, Adrian.
2
4796
by: giddy | last post by:
hi, I have a listview on a form, the View is set to Tile. I also have an image list tied to the *smallImageList property, i have one image in the image list, its a png : 32X32 When i do this, i dont see an icon and the SubItem text! lstvUsers.Columns.Add(Privilege");//added only so the tile detail is
8
5783
by: Lord Zoltar | last post by:
Hi, I've got a list view that displays a series of images. I'd like to be able to draw a divider across the list view to divide the images into groups. Ideally, I'd have a group name, with a line underneath it that spans the ListView. How could this be done? I tried using an image as the divider, but it forced the divider image to be the same size as the image size used for the ImageList that stores the images for the ListView.
0
9671
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10433
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10212
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9035
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4112
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2919
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.