Friday, 15 August 2014

c# - How to add a listViewItem with its own unique image -


Available to add an entry in the ListView C # add Apment methods

  public virtual List View (ListViewItem value) to public virtual ListViewItem (string text) Add public virtual ListViewItem (string text, int imageIndex) Add public virtual ListViewItem (string text string ImageKey) Add public virtual ListViewItem (string key, string text, integer imageIndex) Sir Form on virtual ListViewItem (String key, String text, add string ImageKey)   

Landscape: I ListViewItems with its unique images have a ListView and dynamic as before Columns want to add.

Question: How would you do this?

code I am working

  private void AddToMyList (SomeDataType message) {string Entrykey = message.ID; // Add your 1 column parameter string [] rowEntry = new string [1]; Line entry [0] = message.name; // make it a list view and its line list is indicated by the listITImline = new list view (line entry, (deviceListView.Items.Count- 1)); // Tag the row entry as unique ID line. Tag = Entrykey; // Add the image to the first column row. Image index = 0; // If the image is given for the project then add the image. Images (ENTERTAINMENT, MESSAGES. MARKERMARKER IKON); / LISTView.Items.Add (line) Add the type of lookup to device list at the end;    

There are two things that you need to do

    < Li> Add an image to the image list if it is not already
  • Create a new ListViewItem and assign it an image from the previous point

    This can be done this way based on your code:

      // add marker icons Antrki imagelistforTypeIcons.Images.Add for image insertion (Entrykey, message.marker.markerIcon); // Use the icon from ImageList which is stored under the Entrykey ListViewItem line = New ListViewItem (rowEntry); Line. Images = Entry; // whatever you need a row later. Tag = Entry; ....   

    In the problem with your code (without really trying to do it) you are specifying in the ImageIndex .

    • You are adding a new image to an image list, but assigning an image to a ListViewRow from a different one
    • You You are providing the image index in the constructor but setting it later 0 (why?)
    • You are providing the wrong image index in the first place, because the image in the image list before you add a new image The index of is calculated.

      If your code can be cured in this way:

        // markerIcon Entrykey imagelistforTypeIcons.Images.Add (Entrykey, message.marker.markerIcon) Pair in ImageList; // Use the icon from ImageList which is stored under the Entrykey ListViewItem line = New ListViewItem (rowEntry); Line. Image Index = Type for Icons.Count- 1; // whatever you need a row later. Tag = Entry;    

No comments:

Post a Comment