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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • piercy
    New Member
    • Aug 2007
    • 77

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

    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.

  • piercy
    New Member
    • Aug 2007
    • 77

    #2
    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)
    Code:
    LockWindowUpdate(this.Handle); //Lock the windows main client for refreshing
    
    imageList1.Images.Add(Bitmap.FromFile(Application.StartupPath + "\\Images\\image.gif"));
    
    LockWindowUpdate(IntPtr.Zero); //Unlock all the locked windows
    
    
    Application.DoEvents(); //Refresh all the events in the queu
    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..:

    Code:
    private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
            {
               
                System.Drawing.Point pt = dataGrid1.PointToClient(Cursor.Position);
                listView1.Items.Clear();
                dg1val = dataGrid1[dataGrid1.CurrentCell.RowNumber, 0].ToString();
                dg1val = dg1val.Replace(":","");
                dg1val = dg1val.Replace("/","");
                dg1val = dg1val.Replace(" ","");
                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";
              
    
                try
                {
                   
                    ds1.Tables["Receipitants"].Clear();
                }
                catch { }
                try
                {
                    this.sqlDataAdapter2.Fill(ds1, "Receipitants");
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
               
               
                DataTable temp = this.ds.Tables["Message"];
                foreach (DataRow row in ds1.Tables["Receipitants"].Rows)
                {
                    if (row.ItemArray[1].ToString() != null)
                    {
                        if (row.ItemArray[1].ToString().Length > 0)
                        {
                            ListViewItem lvi = new ListViewItem(new string[] { row.ItemArray[3].ToString() + " (" + row.ItemArray[1].ToString() + ")"},0);
                            lvi.ToolTipText = row.ItemArray[4].ToString();
                            listView1.Items.Add(lvi);
                           
                        }
                        else
                        {
                            ListViewItem lvi = new ListViewItem(row.ItemArray[3].ToString());
                            lvi.ToolTipText = row.ItemArray[4].ToString();
                            lvi.ImageIndex = 1;
                            listView1.Items.Add(lvi);
                        }
                    }
                    else
                    {
                        ListViewItem lvi = new ListViewItem(row.ItemArray[3].ToString());
                        lvi.ToolTipText = row.ItemArray[4].ToString();
                        lvi.ImageIndex = 1;
                        listView1.Items.Add(lvi);
                    }
                }
                string command = "SELECT Subject,Body FROM [Message] WHERE MsgID=@id";
                string message = null;
                string subject = null;
                try
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand(command, conn);
                    cmd.Parameters.Add("@id", SqlDbType.BigInt).Value = dg1val.ToString();
                    SqlDataReader myReader = cmd.ExecuteReader();
                    while (myReader.Read())
                    {
                        subject = myReader[0].ToString();
                        message = myReader[1].ToString();
                    }
    
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(this, "Database Error: " + ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    conn.Close();
                }
                this.richTextBox1.Text = message;
                this.richTextBox2.Text = subject;
                listView1.Refresh();
                Size temp1 = listView1.TileSize;
                temp1.Width = ((listView1.Size.Width - System.Windows.Forms.SystemInformation.VerticalScrollBarWidth)-(3*16)) / 3;
                listView1.TileSize = temp1;
                listView1.Refresh();
    
                this.Refresh();
            }
    Thanks again,
    Piercy

    Comment

    • piercy
      New Member
      • Aug 2007
      • 77

      #3
      Ok, I think i've solved it... Found this post:

      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

      Comment

      • manpakhong
        New Member
        • Aug 2007
        • 3

        #4
        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


        Originally posted by piercy
        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.

        Comment

        Working...