0
ListView listView1 = new ListView();
        DataTable dataTable = new DataTable();
        MoneyReceiptGateway moneyReceiptGateway = new MoneyReceiptGateway();
        dataTable = moneyReceiptGateway.SelectDataForListView(narrationTextBox.Text);
        string[] str = new string[dataTable.Columns.Count];
        foreach (DataRow rr in dataTable.Rows)
        {
            for (int coll = 0; coll <= dataTable.Columns.Count; coll++)
            {
                str[coll] = rr[coll].ToString();
            }
            ListViewDataItem li;
            li = new ListViewDataItem(str);
            listView1.Items.Add(li);
        }
 public DataTable SelectDataForListView(string txtSubHead)
    {
        int length = txtSubHead.Length;
        string aa = txtSubHead.Substring(0, length);
        connection = ConfigurationManager.AppSettings["ConnectionString"];
        sqlConnectionObj = new SqlConnection(this.connection);
        string insertQuery = @"select S.SubName,M.MainName, A.ClassName from AcClass as A, MainClass as M, SubClass as S WHERE (S.AcCode=A.AcCode) and (S.AcCode=M.AcCode) 
                           and (S.MainCode=M.MainCode) and  (substring(S.subname,1,'" + length + "')='" + txtSubHead + "') or (substring(M.MainName,1,'" + length + "')='" + txtSubHead + "' )  ORDER BY S.SubName";
        
        sqlConnectionObj.Open();
        adapter = new SqlDataAdapter(insertQuery, sqlConnectionObj);
        dataTable=new DataTable();
        adapter.Fill(dataTable);
        return dataTable;
    }

error message is:Error 3 The best overloaded method match for 'System.Windows.Forms.ListView.ListViewItemCollection.Add(string)' has some invalid argument

Edited by alam14_mist: n/a

3
Contributors
3
Replies
6
Views
5 Years
Discussion Span
Last Post by alam14_mist
0

It seems to be because you are dimensioning "li" as a ListViewDataItem but then are trying to pass it as a string. Perhaps you should dim it as a string OR leave as is but see if this type has a "ToString()" method when you add it.
(i.e. "...Collection.Add(li.ToString())

0

Are you using the System.Windows.Forms.ListView or the System.Web.UI.WebControls.ListView? From the error (and usage) you are trying to use the Forms one, but then trying to force a web data item into the control. Which did you intend to use?

0

i a m using System.Web.UI.WebControls.ListView
but problem is still on first line
li = new ListViewItem(str);
listView1.Items.Add(li.ToString());
so what to do now?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.