[Mono-bugs] [Bug 470384] New: DataGridView not is formating cells and application throw Exception after delete rows!
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Wed Jan 28 16:35:57 EST 2009
https://bugzilla.novell.com/show_bug.cgi?id=470384
Summary: DataGridView not is formating cells and application
throw Exception after delete rows!
Classification: Mono
Product: Mono: Class Libraries
Version: SVN
Platform: PC
OS/Version: openSUSE 11.1
Status: NEW
Severity: Major
Priority: P5 - None
Component: Windows.Forms
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: rodrigosilvabrito at hotmail.com
QAContact: mono-bugs at lists.ximian.com
Found By: DeveloperNet
Created an attachment (id=268447)
--> (https://bugzilla.novell.com/attachment.cgi?id=268447)
Source Code
Description of Problem:
In MS's runtime this code work fine!
Steps to reproduce the problem:
1. Generate and compile the code!
--Program.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace DataGridViewProblem
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmDataGridProblem());
}
}
}
--frmDataGridProblem.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DataGridViewProblem
{
public partial class frmDataGridProblem : Form
{
BindingList<Cash> list;
public frmDataGridProblem()
{
InitializeComponent();
InitializeGridColums();
list = new BindingList<Cash>();
list.ListChanged += delegate(object sender, ListChangedEventArgs e)
{
if (this.list.Count == 0)
{
this.tsbShowCurrent.Enabled = false;
this.tsbDelete.Enabled = false;
}
};
for (int i = 0; i <= 100; i++)
{
Cash cash = new Cash();
cash.Date = DateTime.Now;
cash.Memo = "Memo " + i.ToString();
cash.Increase = i;
cash.Reduce = (decimal)i / 2;
list.Add(cash);
}
dgvList.DataSource = list;
}
public Cash Selected
{
get
{
return this.dgvList.CurrentRow.DataBoundItem as Cash;
}
set
{
for (int i = 0; i < this.dgvList.Rows.Count; i++)
{
if (value == dgvList.Rows[i].DataBoundItem as Cash)
{
dgvList.Rows[i].Selected = true;
dgvList.CurrentCell = dgvList.Rows[i].Cells[0];
break;
}
}
}
}
private void Find(string lookFor)
{
foreach (Cash cash in this.list)
{
if (lookFor.Length <= cash.Memo.Length)
{
if (cash.Memo.Substring(0, lookFor.Length) == lookFor)
{
this.Selected = cash;
return;
}
}
}
}
private void tsbFind_Click(object sender, EventArgs e)
{
this.Find(tscLookFor.Text);
}
private void tscLookFor_TextChanged(object sender, EventArgs e)
{
if (tscLookFor.Text.Length > 0)
{
tsbFind.Enabled = true;
this.Find(tscLookFor.Text);
}
else
{
tsbFind.Enabled = false;
if (dgvList.Rows.Count > 0)
{
dgvList.Rows[0].Selected = true;
dgvList.CurrentCell = dgvList.Rows[0].Cells[0];
}
}
}
private void tsbShowCurrent_Click(object sender, EventArgs e)
{
if (this.list.Count > 0)
MessageBox.Show(this.Selected.Memo);
}
private void tsbDelete_Click(object sender, EventArgs e)
{
if (this.list.Count > 0)
{
Cash cash = this.Selected;
int pos = this.list.IndexOf(cash);
this.list.Remove(cash);
if (this.list.Count > 0)
{
if (pos == this.list.Count)
this.Selected = this.list[pos - 1];
else
this.Selected = this.list[pos];
}
}
}
private void frmDataGridProblem_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
this.tsbDelete_Click(this, e);
}
}
private void InitializeGridColums()
{
this.dgvList.AutoGenerateColumns = false;
this.gridDateCellStyle = new DataGridViewCellStyle();
this.gridDateCellStyle.Format = "dd/MM/yyyy";
this.colDate = new DataGridViewTextBoxColumn();
this.colDate.DataPropertyName = "Date";
this.colDate.HeaderText = "Date";
this.colDate.Name = "colDate";
this.colDate.ReadOnly = true;
this.colDate.Width = 110;
this.colDate.DefaultCellStyle = this.gridDateCellStyle;
this.colMemo = new DataGridViewTextBoxColumn();
this.colMemo.DataPropertyName = "Memo";
this.colMemo.HeaderText = "Memo";
this.colMemo.Name = "colMemo";
this.colMemo.ReadOnly = true;
this.colMemo.Width = 250;
this.gridMoneyCellStyle = new DataGridViewCellStyle();
this.gridMoneyCellStyle.Alignment =
DataGridViewContentAlignment.MiddleRight;
this.gridMoneyCellStyle.Format = "N2";
this.colIncrease = new DataGridViewTextBoxColumn();
this.colIncrease.DataPropertyName = "Increase";
this.colIncrease.HeaderText = "Increase";
this.colIncrease.Name = "colIncrease";
this.colIncrease.ReadOnly = true;
this.colIncrease.Width = 100;
this.colIncrease.DefaultCellStyle = this.gridMoneyCellStyle;
this.colReduce = new DataGridViewTextBoxColumn();
this.colReduce.DataPropertyName = "Reduce";
this.colReduce.HeaderText = "Reduce";
this.colReduce.Name = "colReduce";
this.colReduce.ReadOnly = true;
this.colReduce.Width = 100;
this.colReduce.DefaultCellStyle = this.gridMoneyCellStyle;
this.dgvList.Columns.AddRange(new
System.Windows.Forms.DataGridViewColumn[] {
this.colDate,
this.colMemo,
this.colIncrease,
this.colReduce});
}
private DataGridViewCellStyle gridMoneyCellStyle;
private DataGridViewCellStyle gridDateCellStyle;
private DataGridViewTextBoxColumn colDate;
private DataGridViewTextBoxColumn colMemo;
private DataGridViewTextBoxColumn colIncrease;
private DataGridViewTextBoxColumn colReduce;
}
public class Cash
{
private Nullable<DateTime> date = DateTime.Today;
private string memo = string.Empty;
private decimal increase = 0;
private decimal reduce = 0;
public Nullable<DateTime> Date
{
get { return date; }
set { date = value; }
}
public string Memo
{
get { return memo; }
set { memo = value; }
}
public decimal Increase
{
get { return increase; }
set { increase = value; }
}
public decimal Reduce
{
get { return reduce; }
set { reduce = value; }
}
}
}
--frmDataGridProblem.Designer.cs
namespace DataGridViewProblem
{
partial class frmDataGridProblem
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new
System.ComponentModel.ComponentResourceManager(typeof(frmDataGridProblem));
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 =
new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 =
new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 =
new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 =
new System.Windows.Forms.DataGridViewCellStyle();
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.tslSearch = new System.Windows.Forms.ToolStripLabel();
this.tscLookFor = new System.Windows.Forms.ToolStripComboBox();
this.tsbFind = new System.Windows.Forms.ToolStripButton();
this.tsbDelete = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator1 = new
System.Windows.Forms.ToolStripSeparator();
this.tsbShowCurrent = new System.Windows.Forms.ToolStripButton();
this.dgvList = new System.Windows.Forms.DataGridView();
this.toolStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvList)).BeginInit();
this.SuspendLayout();
//
// toolStrip1
//
this.toolStrip1.GripStyle =
System.Windows.Forms.ToolStripGripStyle.Hidden;
this.toolStrip1.Items.AddRange(new
System.Windows.Forms.ToolStripItem[] {
this.tslSearch,
this.tscLookFor,
this.tsbFind,
this.tsbDelete,
this.toolStripSeparator1,
this.tsbShowCurrent});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(584, 25);
this.toolStrip1.TabIndex = 0;
this.toolStrip1.TabStop = true;
//
// tslSearch
//
this.tslSearch.Name = "tslSearch";
this.tslSearch.Size = new System.Drawing.Size(60, 22);
this.tslSearch.Text = "Look for: ";
//
// tscLookFor
//
this.tscLookFor.FlatStyle =
System.Windows.Forms.FlatStyle.Standard;
this.tscLookFor.Name = "tscLookFor";
this.tscLookFor.Size = new System.Drawing.Size(121, 25);
this.tscLookFor.TextChanged += new
System.EventHandler(this.tscLookFor_TextChanged);
//
// tsbFind
//
this.tsbFind.DisplayStyle =
System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.tsbFind.Enabled = false;
this.tsbFind.Image =
((System.Drawing.Image)(resources.GetObject("tsbFind.Image")));
this.tsbFind.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tsbFind.Name = "tsbFind";
this.tsbFind.Size = new System.Drawing.Size(34, 22);
this.tsbFind.Text = "&Find";
this.tsbFind.Click += new System.EventHandler(this.tsbFind_Click);
//
// tsbDelete
//
this.tsbDelete.Alignment =
System.Windows.Forms.ToolStripItemAlignment.Right;
this.tsbDelete.DisplayStyle =
System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.tsbDelete.Image =
((System.Drawing.Image)(resources.GetObject("tsbDelete.Image")));
this.tsbDelete.ImageTransparentColor =
System.Drawing.Color.Magenta;
this.tsbDelete.Name = "tsbDelete";
this.tsbDelete.Size = new System.Drawing.Size(113, 22);
this.tsbDelete.Text = "Delete entry <DEL>";
this.tsbDelete.Click += new
System.EventHandler(this.tsbDelete_Click);
//
// toolStripSeparator1
//
this.toolStripSeparator1.Alignment =
System.Windows.Forms.ToolStripItemAlignment.Right;
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25);
//
// tsbShowCurrent
//
this.tsbShowCurrent.Alignment =
System.Windows.Forms.ToolStripItemAlignment.Right;
this.tsbShowCurrent.DisplayStyle =
System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.tsbShowCurrent.Image =
((System.Drawing.Image)(resources.GetObject("tsbShowCurrent.Image")));
this.tsbShowCurrent.ImageTransparentColor =
System.Drawing.Color.Magenta;
this.tsbShowCurrent.Name = "tsbShowCurrent";
this.tsbShowCurrent.Size = new System.Drawing.Size(81, 22);
this.tsbShowCurrent.Text = "Show current";
this.tsbShowCurrent.Click += new
System.EventHandler(this.tsbShowCurrent_Click);
//
// dgvList
//
this.dgvList.AllowUserToAddRows = false;
this.dgvList.AllowUserToDeleteRows = false;
this.dgvList.AllowUserToOrderColumns = true;
this.dgvList.AllowUserToResizeRows = false;
dataGridViewCellStyle1.BackColor =
System.Drawing.Color.FromArgb(((int)(((byte)(238)))), ((int)(((byte)(238)))),
((int)(((byte)(238)))));
this.dgvList.AlternatingRowsDefaultCellStyle =
dataGridViewCellStyle1;
this.dgvList.BackgroundColor = System.Drawing.Color.GhostWhite;
this.dgvList.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.dgvList.ColumnHeadersBorderStyle =
System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
dataGridViewCellStyle2.BackColor =
System.Drawing.Color.LightSteelBlue;
dataGridViewCellStyle2.Font = new System.Drawing.Font("Tahoma",
8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((byte)(0)));
dataGridViewCellStyle2.ForeColor =
System.Drawing.SystemColors.ControlDarkDark;
dataGridViewCellStyle2.SelectionBackColor =
System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle2.SelectionForeColor =
System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle2.WrapMode =
System.Windows.Forms.DataGridViewTriState.True;
this.dgvList.ColumnHeadersDefaultCellStyle =
dataGridViewCellStyle2;
this.dgvList.ColumnHeadersHeight = 20;
this.dgvList.ColumnHeadersHeightSizeMode =
System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
this.dgvList.Dock = System.Windows.Forms.DockStyle.Fill;
this.dgvList.Location = new System.Drawing.Point(0, 25);
this.dgvList.MultiSelect = false;
this.dgvList.Name = "dgvList";
this.dgvList.ReadOnly = true;
this.dgvList.RowHeadersBorderStyle =
System.Windows.Forms.DataGridViewHeaderBorderStyle.None;
dataGridViewCellStyle3.BackColor =
System.Drawing.SystemColors.ButtonFace;
dataGridViewCellStyle3.Font = new System.Drawing.Font("Tahoma",
8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((byte)(0)));
dataGridViewCellStyle3.ForeColor =
System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle3.SelectionBackColor =
System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle3.SelectionForeColor =
System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle3.WrapMode =
System.Windows.Forms.DataGridViewTriState.True;
this.dgvList.RowHeadersDefaultCellStyle = dataGridViewCellStyle3;
this.dgvList.RowHeadersVisible = false;
this.dgvList.RowHeadersWidth = 4;
dataGridViewCellStyle4.SelectionBackColor =
System.Drawing.Color.FromArgb(((int)(((byte)(37)))), ((int)(((byte)(73)))),
((int)(((byte)(84)))));
dataGridViewCellStyle4.SelectionForeColor =
System.Drawing.Color.White;
this.dgvList.RowsDefaultCellStyle = dataGridViewCellStyle4;
this.dgvList.RowTemplate.DefaultCellStyle.Font = new
System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.dgvList.RowTemplate.Height = 18;
this.dgvList.SelectionMode =
System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dgvList.Size = new System.Drawing.Size(584, 347);
this.dgvList.TabIndex = 1;
//
// frmDataGridProblem
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(584, 372);
this.Controls.Add(this.dgvList);
this.Controls.Add(this.toolStrip1);
this.KeyPreview = true;
this.Name = "frmDataGridProblem";
this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "DataGridView not is formating cells!";
this.KeyDown += new
System.Windows.Forms.KeyEventHandler(this.frmDataGridProblem_KeyDown);
this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvList)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ToolStrip toolStrip1;
private System.Windows.Forms.ToolStripButton tsbShowCurrent;
private System.Windows.Forms.DataGridView dgvList;
private System.Windows.Forms.ToolStripLabel tslSearch;
private System.Windows.Forms.ToolStripButton tsbFind;
private System.Windows.Forms.ToolStripComboBox tscLookFor;
private System.Windows.Forms.ToolStripButton tsbDelete;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
}
}
2. Execute the program in mono linux and select with mouse click the 10º row
'Memo 9' and keep mouse arrow over row, press DELETE key until all rows be
deleted, then move mouse arrow over grid --> app then throw:
System.ArgumentOutOfRangeException: Index is less than 0 or more than or equal
to the list count.
Parameter name: index
0
at System.Collections.ArrayList.ThrowNewArgumentOutOfRangeException
(System.String name, System.Object actual, System.String message) [0x00000]
at System.Collections.ArrayList.get_Item (Int32 index) [0x00000]
at System.Windows.Forms.DataGridViewRowCollection.SharedRow (Int32 rowIndex)
[0x00000]
at System.Windows.Forms.DataGridView.GetRowInternal (Int32 rowIndex)
[0x00000]
at System.Windows.Forms.DataGridView.GetCellInternal (Int32 colIndex, Int32
rowIndex) [0x00000]
at System.Windows.Forms.DataGridView.OnCellMouseLeave
(System.Windows.Forms.DataGridViewCellEventArgs e) [0x00000]
at System.Windows.Forms.DataGridView.OnMouseMove
(System.Windows.Forms.MouseEventArgs e) [0x00000]
at System.Windows.Forms.Control.WmMouseMove (System.Windows.Forms.Message& m)
[0x00000]
at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message& m)
[0x00000]
at System.Windows.Forms.DataGridView.WndProc (System.Windows.Forms.Message&
m) [0x00000]
at System.Windows.Forms.Control+ControlWindowTarget.OnMessage
(System.Windows.Forms.Message& m) [0x00000]
at System.Windows.Forms.Control+ControlNativeWindow.WndProc
(System.Windows.Forms.Message& m) [0x00000]
at System.Windows.Forms.NativeWindow.WndProc (IntPtr hWnd, Msg msg, IntPtr
wParam, IntPtr lParam) [0x00000]
When delete all rows and mouse is out of grid area, no exception.
In MS's runtime execute normal. In MONO Suse Linux 11.1 bug's.
DataGridViewCellStyle is not properly formatting the cells
In source code:
this.gridDateCellStyle.Format = "dd/MM/yyyy";
this.gridMoneyCellStyle.Format = "N2";
Following attachments with images of the application running in. NET Framework
and Mono, to show the problems with the formatting.
Expected Results:
Correct formatting and no throw after delete rows
How often does this happen?
Ever, All!
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list