473,387 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

77
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.Images.Add(Bitmap.FromFile(Application. StartupPath + "\\Images\\image.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 5713
piercy
77
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
Ok, I think i've solved it... Found this post:
http://rikkus.info/workaround-to-lis...ng-images.html
And after moving enablevisualstyle 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
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@hotmail.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.Images.Add(Bitmap.FromFile(Application. StartupPath + "\\Images\\image.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
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...
2
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...
1
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...
4
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...
3
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...
11
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? ...
1
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...
2
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...
8
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.