Samik Sengupta
Samik Sengupta

Reputation: 1973

Custom Form not showing

I've designed a Windows Form in C#.NET using the visual editor. I want to call this form from another form. But the form is not detected from another form. The designed from is called DataList and the main code is as follows-

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DataList
{
    public partial class DataList : Form
    {
        //code, functions etc.
    }
}

When I call it from another form using DataList.Show(); it highlights DataList with the error - The name DataList does not exist in the current context.

What could be wrong?

Upvotes: 0

Views: 112

Answers (3)

use static for the class then you can run class.show();

Upvotes: 0

Alvin Wong
Alvin Wong

Reputation: 12420

DataList is a class in which you can't call any non-static functions/methods directly.

You need to create an instance of it.

(new DataList()).Show();

Or probably

DataList myDataList;
myDataList = new DataList();
myDataList.Show();

// Do whatever you want?

If, in case, it still fails, then that is the namespace issue.

Upvotes: 2

andy
andy

Reputation: 6079

Dont use NameSpace Name and Class Name SAME.

Go with this Link

Upvotes: 0

Related Questions