Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

How can i convert or make a wraper so listView will accept/add object[] ?

$
0
0

In listBox there is no problem. I can do:

listBoxSnap.Items.AddRange(WindowSnap.GetAllWindows(true, true).ToArray());


But in listView:

ListViewCostumControl.lvnf.Items.AddRange(WindowSnap.GetAllWindows(true, true).ToArray());


The errors:

Error1The best overloaded method match for 'System.Windows.Forms.ListView.ListViewItemCollection.AddRange(System.Windows.Forms.ListViewItem[])' has some invalid argumentse:\c-drive-backup\temp\capture\form1.cs

Error2Argument 1: cannot convert from 'MinimizeCapture.WindowSnapCollection' to 'System.Windows.Forms.ListViewItem[]'e:\c-drive-backup\temp\capture\form1.cs

This is the GetAllWindows method

public static WindowSnapCollection GetAllWindows(bool minimized, bool specialCapturring)
        {
            windowSnaps = new WindowSnapCollection();
            countMinimizedWindows = minimized;//set minimized flag capture
            useSpecialCapturing = specialCapturring;//set specialcapturing flag
            EnumWindowsCallbackHandler callback = new EnumWindowsCallbackHandler(EnumWindowsCallback);
            EnumWindows(callback, IntPtr.Zero);
            return new WindowSnapCollection(windowSnaps.ToArray(), true);
        }

And this is the ListViewCostumControl code somehow in this code i think i need to add a wrapper or a method to make it to accept either ListViewIrm[] or like the listBox to be able to add object[] or what it need.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MinimizeCapture
{
    public partial class ListViewCostumControl : UserControl
    {


        Object myObj = new Object();
        ListViewItem[] items = new ListViewItem[8];



        public static ListViewControl lvnf;

        public ListViewCostumControl()
        {
            InitializeComponent();

            items[0].Text = myObj.ToString();
            items[0].Tag = myObj;
            lvnf.Items.AddRange(items);


            lvnf = new ListViewControl();
            lvnf.Location = new Point(50, 50);
            lvnf.Size = new Size(50, 50);
            lvnf.View = View.SmallIcon;
            lvnf.Dock = DockStyle.Fill;
            lvnf.SuspendLayout();
            lvnf.LabelEdit = true;
            lvnf.Sorting = SortOrder.None;
            this.Controls.Add(lvnf);
            lvnf.ResumeLayout(false);
        }

        public class ListViewControl : System.Windows.Forms.ListView
        {
            public ListViewControl()
            {
                this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
                this.SetStyle(ControlStyles.EnableNotifyMessage, true);
            }

            protected override void OnNotifyMessage(System.Windows.Forms.Message m)
            {
                if (m.Msg != 0x14)
                {
                    base.OnNotifyMessage(m);
                }
            }
        }

        private void ListViewNFTest_Load(object sender, EventArgs e)
        {

        }
    }
}

Maybe a wrapper or a method so i can select what format of the data the listView will be able to get.


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>