[Mono-winforms-list] ScrollBars.None prevents to show the last row of DataGridView

luisrl larlxz at gmail.com
Fri Jul 23 12:16:20 EDT 2010


Show the last row of the DataGridView automatically after adding a new row.


When DataGridView.ScrollBars = Scrollbars.None, then the DataGridView does
not show the last row.

The objetive worked in:

Windows 2000, XP, Vista, 7, etc.
.NET Framework 2.0, 3.5 and 4.0

The problem happened in:

Ubuntu 10.04
Mono 2.4.4

Windows Server 2008
Mono 2.6.7

How to use the code:

Press the button called "Add" to add a row.
Keep pressing the button called "Add" to see how the list is growing and the
grid keeps showing the last row when the scrollbar is visible. It works

Now, press the button called "Bars" to set the ScrollBars to
"Scrollbars.None". The Scrollbar will disappear.
Continue pressing the button called "Add" to see that the grid won't show
the last row.


For user interface purposes, I need to set ScrollBars.None; but when I set
that, the objetive fails in mono.

Any suggestion about how to solve it?



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

namespace WindowsFormsApplication1
    public partial class Form1 : Form
        DataGridView Grid = new DataGridView();
        DataTable Dt = new DataTable();

        public Form1()

        private void Form1_Load(object sender, EventArgs e)
            //Resize the form

            this.Height = 250;
            this.Width = 400;

            //Create the columns of the table

            Dt.Columns.Add("One", typeof(string));
            Dt.Columns.Add("Two", typeof(string));

            //Set the grid

            Grid.AllowUserToAddRows = false;
            Grid.AllowUserToDeleteRows = false;
            Grid.Height = 150;
            Grid.Location = new Point(50, 0);
            Grid.Width = 300;

            Button BtnAdd = new Button();

            BtnAdd.Height = 25;
            BtnAdd.Location = new Point(50, 175);
            BtnAdd.Width = 50;
            BtnAdd.Text = "Add";

            BtnAdd.Click += new System.EventHandler(this.BtnAdd_Click);

            //Create the "What if..." button

            Button BtnIf = new Button();

            BtnIf.Height = 25;
            BtnIf.Location = new Point(150, 175);
            BtnIf.Width = 50;
            BtnIf.Text = "Bars";

            BtnIf.Click += new System.EventHandler(this.BtnIf_Click);

            //Add the controls to the form



            Grid.DataSource = Dt;

        private void Add()
            //Add a row

            DataRow Row = Dt.NewRow();

            Row["One"] = "Can you";
            Row["Two"] = "see me?";


            if (Grid.Rows.Count > 0)
                int Count = Grid.Rows.Count;

                Grid.CurrentCell = Grid.Rows[Count - 1].Cells["One"];

        private void BtnAdd_Click(object sender, EventArgs e)
            catch (Exception ex)

        private void BtnIf_Click(object sender, EventArgs e)
                if (Grid.ScrollBars == ScrollBars.Both)
                    Grid.ScrollBars = ScrollBars.None;
                    Grid.ScrollBars = ScrollBars.Both;
            catch (Exception ex)
View this message in context: http://mono.1490590.n4.nabble.com/ScrollBars-None-prevents-to-show-the-last-row-of-DataGridView-tp2300409p2300409.html
Sent from the Mono - WinForms mailing list archive at Nabble.com.

More information about the Mono-winforms-list mailing list