[Mono-bugs] [Bug 449312] New: Mono DataGridView no work as expected! Return NULL DataBoundItem. In Mono

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Nov 26 10:23:42 EST 2008


https://bugzilla.novell.com/show_bug.cgi?id=449312


           Summary: Mono DataGridView no work as expected! Return NULL
                    DataBoundItem. In Mono
           Product: Mono: Class Libraries
           Version: 2.0.x
          Platform: PC
        OS/Version: openSUSE 11.0
            Status: NEW
          Severity: Blocker
          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


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();

            list = new BindingList<Cash>();

            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 = 0;

                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 showCurrentRegisterToolStripMenuItem_Click(object sender,
EventArgs e)
        {
            MessageBox.Show(this.Selected.Memo);
        }
    }

    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.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 =
new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 =
new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 =
new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 =
new System.Windows.Forms.DataGridViewCellStyle();
            this.dgvList = new System.Windows.Forms.DataGridView();
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.showCurrentRegisterToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
           
((System.ComponentModel.ISupportInitialize)(this.dgvList)).BeginInit();
            this.menuStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // dgvList
            // 
            this.dgvList.AllowUserToAddRows = false;
            this.dgvList.AllowUserToDeleteRows = false;
            this.dgvList.AllowUserToOrderColumns = true;
            this.dgvList.AllowUserToResizeRows = false;
            dataGridViewCellStyle5.BackColor =
System.Drawing.Color.FromArgb(((int)(((byte)(238)))), ((int)(((byte)(238)))),
((int)(((byte)(238)))));
            this.dgvList.AlternatingRowsDefaultCellStyle =
dataGridViewCellStyle5;
            this.dgvList.BackgroundColor = System.Drawing.Color.GhostWhite;
            this.dgvList.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.dgvList.ColumnHeadersBorderStyle =
System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
            dataGridViewCellStyle6.BackColor =
System.Drawing.Color.LightSteelBlue;
            dataGridViewCellStyle6.Font = new System.Drawing.Font("Tahoma",
8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((byte)(0)));
            dataGridViewCellStyle6.ForeColor =
System.Drawing.SystemColors.ControlDarkDark;
            dataGridViewCellStyle6.SelectionBackColor =
System.Drawing.SystemColors.Highlight;
            dataGridViewCellStyle6.SelectionForeColor =
System.Drawing.SystemColors.HighlightText;
            dataGridViewCellStyle6.WrapMode =
System.Windows.Forms.DataGridViewTriState.True;
            this.dgvList.ColumnHeadersDefaultCellStyle =
dataGridViewCellStyle6;
            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, 24);
            this.dgvList.MultiSelect = false;
            this.dgvList.Name = "dgvList";
            this.dgvList.RowHeadersBorderStyle =
System.Windows.Forms.DataGridViewHeaderBorderStyle.None;
            dataGridViewCellStyle7.BackColor =
System.Drawing.SystemColors.ButtonFace;
            dataGridViewCellStyle7.Font = new System.Drawing.Font("Tahoma",
8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((byte)(0)));
            dataGridViewCellStyle7.ForeColor =
System.Drawing.SystemColors.WindowText;
            dataGridViewCellStyle7.SelectionBackColor =
System.Drawing.SystemColors.Highlight;
            dataGridViewCellStyle7.SelectionForeColor =
System.Drawing.SystemColors.HighlightText;
            dataGridViewCellStyle7.WrapMode =
System.Windows.Forms.DataGridViewTriState.True;
            this.dgvList.RowHeadersDefaultCellStyle = dataGridViewCellStyle7;
            this.dgvList.RowHeadersVisible = false;
            this.dgvList.RowHeadersWidth = 4;
            dataGridViewCellStyle8.SelectionBackColor =
System.Drawing.Color.FromArgb(((int)(((byte)(37)))), ((int)(((byte)(73)))),
((int)(((byte)(84)))));
            dataGridViewCellStyle8.SelectionForeColor =
System.Drawing.Color.White;
            this.dgvList.RowsDefaultCellStyle = dataGridViewCellStyle8;
            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(559, 358);
            this.dgvList.TabIndex = 6;
            this.dgvList.TabStop = false;
            // 
            // menuStrip1
            // 
            this.menuStrip1.Items.AddRange(new
System.Windows.Forms.ToolStripItem[] {
            this.showCurrentRegisterToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(559, 24);
            this.menuStrip1.TabIndex = 7;
            this.menuStrip1.Text = "menuStrip1";
            // 
            // showCurrentRegisterToolStripMenuItem
            // 
            this.showCurrentRegisterToolStripMenuItem.Name =
"showCurrentRegisterToolStripMenuItem";
            this.showCurrentRegisterToolStripMenuItem.Size = new
System.Drawing.Size(89, 20);
            this.showCurrentRegisterToolStripMenuItem.Text = "Show current";
            this.showCurrentRegisterToolStripMenuItem.Click += new
System.EventHandler(this.showCurrentRegisterToolStripMenuItem_Click);
            // 
            // frmDataGridProblem
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(559, 382);
            this.Controls.Add(this.dgvList);
            this.Controls.Add(this.menuStrip1);
            this.MainMenuStrip = this.menuStrip1;
            this.Name = "frmDataGridProblem";
            this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "DataGridView not is implemented!";
           
((System.ComponentModel.ISupportInitialize)(this.dgvList)).EndInit();
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.DataGridView dgvList;
        private System.Windows.Forms.MenuStrip menuStrip1;
        private System.Windows.Forms.ToolStripMenuItem
showCurrentRegisterToolStripMenuItem;
    }
}

2. Execute the program and select any row and click in button 'Show Current',
in MS's runtime execute normal. In MONO Suse Linux 11 bug's.

Actual Results:
     this.dgvList.CurrentRow.DataBoundItem return null

rodrigo at DMS-MOBILE:/shared/Debug> mono DataGridViewProblem.exe
Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object
  at
DataGridViewProblem.frmDataGridProblem.showCurrentRegisterToolStripMenuItem_Click
(System.Object sender, System.EventArgs e) [0x00000] 
  at System.Windows.Forms.ToolStripItem.OnClick (System.EventArgs e) [0x00000] 
  at System.Windows.Forms.ToolStripMenuItem.OnClick (System.EventArgs e)
[0x00000] 
  at System.Windows.Forms.ToolStripMenuItem.HandleClick (System.EventArgs e)
[0x00000] 
  at System.Windows.Forms.ToolStripItem.FireEvent (System.EventArgs e,
ToolStripItemEventType met) [0x00000] 
  at (wrapper remoting-invoke-with-check)
System.Windows.Forms.ToolStripItem:FireEvent
(System.EventArgs,System.Windows.Forms.ToolStripItemEventType)
  at System.Windows.Forms.ToolStrip.OnMouseUp
(System.Windows.Forms.MouseEventArgs mea) [0x00000] 
  at System.Windows.Forms.Control.WmLButtonUp (System.Windows.Forms.Message& m)
[0x00000] 
  at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message& m)
[0x00000] 
  at System.Windows.Forms.ScrollableControl.WndProc
(System.Windows.Forms.Message& m) [0x00000] 
  at System.Windows.Forms.ToolStrip.WndProc (System.Windows.Forms.Message& m)
[0x00000] 
  at System.Windows.Forms.MenuStrip.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] 
  at System.Windows.Forms.XplatUIX11.DispatchMessage (System.Windows.Forms.MSG&
msg) [0x00000] 
  at System.Windows.Forms.XplatUI.DispatchMessage (System.Windows.Forms.MSG&
msg) [0x00000] 
  at System.Windows.Forms.Application.RunLoop (Boolean Modal,
System.Windows.Forms.ApplicationContext context) [0x00000] 
  at System.Windows.Forms.Application.Run
(System.Windows.Forms.ApplicationContext context) [0x00000] 
  at System.Windows.Forms.Application.Run (System.Windows.Forms.Form mainForm)
[0x00000] 
  at DataGridViewProblem.Program.Main () [0x00000] 


Expected Results:
     Is expected --> this.dgvList.CurrentRow.DataBoundItem return the Entity
for row selected!


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