[Mono-winforms-list] ScrollBars.None prevents to show the last row of DataGridView
Stifu
stifu at free.fr
Fri Jul 23 13:45:34 EDT 2010
Please file a bug report with a complete test case.
http://mono-project.com/Bugs
luisrl wrote:
>
> Objetive:
>
> Show the last row of the DataGridView automatically after adding a new
> row.
>
> Problem:
>
> 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 fine.
>
> 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.
>
> Reason:
>
> 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?
>
> Thanks
>
> Code:
>
> 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()
> {
> InitializeComponent();
> }
>
> 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
>
> this.Controls.Add(Grid);
> this.Controls.Add(BtnAdd);
> this.Controls.Add(BtnIf);
>
> //Bind
>
> Grid.DataSource = Dt;
> }
>
> private void Add()
> {
> //Add a row
>
> DataRow Row = Dt.NewRow();
>
> Row["One"] = "Can you";
> Row["Two"] = "see me?";
>
> Dt.Rows.Add(Row);
>
> 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)
> {
> try
> {
> Add();
> }
> catch (Exception ex)
> {
> MessageBox.Show(ex.Message);
> }
> }
>
> private void BtnIf_Click(object sender, EventArgs e)
> {
> try
> {
> if (Grid.ScrollBars == ScrollBars.Both)
> {
> Grid.ScrollBars = ScrollBars.None;
> }
> else
> {
> Grid.ScrollBars = ScrollBars.Both;
> }
> }
> catch (Exception ex)
> {
> MessageBox.Show(ex.Message);
> }
> }
> }
> }
>
--
View this message in context: http://mono.1490590.n4.nabble.com/ScrollBars-None-prevents-to-show-the-last-row-of-DataGridView-tp2300409p2300511.html
Sent from the Mono - WinForms mailing list archive at Nabble.com.
More information about the Mono-winforms-list
mailing list