Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am making dll file and for this pupose i created class library project and added class ListView
In my class library project listview properties are showing. Below code works in class in windows form project but same code does not work in class library project.
I am using below code into class library
VB.NET
Imports System.Windows.Forms
Imports System.Data.SqlClient
Public Class ListView
    Public Shared Function FillListView(ByVal lvw As ListView, ByVal dt As DataTable)
        lvw.view = View.Details
        lvw.GridLines = True
        lvw.FullRowSelect = True
        lvw.Columns.Clear()
        lvw.Items.Clear()
     End Function
End Class 


In this code following lines giving error.It says view is not a member of DbLib.ListView and it says same about Gridlines, FullRowSelect, Columns.Items etc.
VB.NET
lvw.view = View.Details
lvw.GridLines = True
lvw.FullRowSelect = True
lvw.Columns.Clear()
lvw.Items.Clear()

I hope for help and guidence. Please help me.
Posted

1 solution

You should not name your class ListView, because there already is such a class defined in System.Windows.Forms namespace.

Better do:
C#
using System.Windows.Forms;

public class MyListView : ListView
{
   // ...
}


This way you will inherit tthe base ListView class, and be able to use all its existent properties and methods.
 
Share this answer
 
v2
Comments
Rizwan Chattha 3-Dec-15 5:05am    
I changed name to LView but same error still exist.
phil.o 3-Dec-15 5:25am    
Because C# is case-sensitive, and you should write View instead of view. And set your class as inheriting ListView.
Rizwan Chattha 3-Dec-15 5:29am    
I am using vb.net. and how to set class inheriting ListView.
Rizwan Chattha 3-Dec-15 5:43am    
This code works "Inherits System.Windows.Forms.ListView"
but now new error showing. This line has error "For Each col As DataColumn In dt.Columns"
here dt.Columns
Public Shared Function FillListView(ByVal lvw As LView, ByVal dt As DataTable)
For Each col As DataColumn In dt.Columns
lvw.Columns.Add(col.ToString)
Next
End Function

In above code dt.Columns giving error. It says "Column is not member of DbLib.DataTable.
I tried to inherit it by using below line code
"Inherits System.Windows.Forms.DataTable"
but this line also giving error "Inherits can appear only one in class statemen and can specify only one class".
Rizwan Chattha 3-Dec-15 5:33am    
This code works into class in case of windows form project. But it is not working only in case of class library project because i want to create dll file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900