Im new in C# and facing a problem. I have a link label which shows the DataGridview on click. I would like to do this thing in classes. Can anybody tell me that how can I do it in a seperate class?

Recommended Answers

All 6 Replies

While I understand the end result you want, I'm not sure what you mean by doing it in a separate class. Can you be more specific?

If you simply want to show and hide the DataGridView (DGV) when a particular label is clicked you only need check if the DGV is visible or not and then do DataGridView.Visible = true; (or = false if you want to hide the DGV), within the predefined clicked method for the label.

If the DGV and the label are both on the same form this can all be done in the one class behind that form.

here is the coding of the main form and class but its not working.

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

namespace GymManagementSys1

    public partial class Main_Screen : Form
    {
        Insert_Attendance IA = new Insert_Attendance();
        public Main_Screen()
        {
            InitializeComponent();

        }

        private void Main_Screen_Load(object sender, EventArgs e)
        {
            AttendanceData.Hide();
        }

        private void AttendanceLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            IA.showGrid();
        }

    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GymManagementSys1
{
    class Insert_Attendance
    {
        public void showGrid()
        {
            DataGridView AttendanceData = new DataGridView();
            AttendanceData.Show();
        }
    }
}

Just creating a DataGridView will not do very much.
You have to initialize several things.
Here is a snippet to put you on track.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.