Home > Blockchain >  Winform Scrollbar don't show up on script initialized Datagridview
Winform Scrollbar don't show up on script initialized Datagridview

Time:10-19

I have a problem with my script initialized DataGridView. I tried a lot of solution prior to post this question and made a lot of research.

Here is the problem, when I use the method above, I can't see the scrollbar.


public void AddNewPanTab(TabControl tab, ComboBox panIndex)
        {
            

            tab.TabPages.Add("Panneau "   tab.TabCount);


            DataGridViewDragNDrop dragNDrop = new DataGridViewDragNDrop();
            DataGridView panGridView = new DataGridView();
            panGridView.Name = "panGridView_"   tab.TabCount;
            
            panGridView.RowTemplate.Height = 24;
            panGridView.Size = new System.Drawing.Size(1375, 458);
            panGridView.Columns.Add("id", "id");
            panGridView.Columns.Add("part_code", "part_code");
            panGridView.Columns.Add("description", "description");
            panGridView.Columns.Add("size", "size");
            panGridView.Columns.Add("manufacturier", "manufacturier");
            panGridView.Columns.Add("distributeur", "distributeur");
            panGridView.Columns.Add("prix", "prix");
            panGridView.Columns.Add("revise", "revise");
            panGridView.Columns.Add("date_revision", "date_revision");
            panGridView.Columns.Add("Quantité", "Quantité");
            panGridView.Columns[0].Width = 100;
            panGridView.Columns[1].Width = 150;
            panGridView.Columns[2].Width = 250;
            panGridView.Columns[3].Width = 100;
            panGridView.Columns[4].Width = 100;
            panGridView.Columns[9].Width = 75;
            dragNDrop.view = panGridView;
            
            panIndex.Items.Add(tab.TabCount - 1);
            panGridView.CellMouseDown  = dragNDrop.DataGridView_CellMouseDown;
            panGridView.MouseMove  = dragNDrop.dataGridView_MouseMove;
            panGridView.MouseUp  = dragNDrop.dataGridView_MouseUp;
            


            
            tab.TabPages[tab.TabCount - 1].Controls.Add(panGridView);
            


        }

I tried

panGridView.ScrollBars = System.Windows.Forms.ScrollBars.Both;

without any result. I have access to the data grid because I populate it and drag and drop rows and do A lot of thing with data into the DataGridView.

I checked that the DWG is smaller than his parent tabs.

I just can't figure what is happening. If I add a dwg from the toolbox, I can show or hide the scrollbar from his properties and I supposed it's the same for script dwg.

Maybe the problem comes from the parent relation but I don't know.

here is a picture of the situation

the image below is my application

CodePudding user response:

Here you go... though I don't know what you did wrong, since your code is not complete...

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 TestDGVScroll
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            DataGridView dgv = new DataGridView();
            dgv.ScrollBars = ScrollBars.Both;
            dgv.Dock = DockStyle.Fill;
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("COL"));
            dt.Columns.Add(new DataColumn("COL2"));
            dt.Columns.Add(new DataColumn("COL3"));
            DataRow dr;
            for (int index = 0; index < 100; index  )
            {
                dr = dt.NewRow();
                dr["COL"] = index;
                dr["COL2"] = index   1;
                dr["COL3"] = index   2;
                dt.Rows.Add(dr);
            }

            dgv.DataSource = dt;
            panel1.Controls.Add(dgv);
        }
    }
}

Image of DGV with scrollbars

  • Related