[Mono-winforms-list] DataGridView DataBoundItem return NULL
RodrigoBrito
rodrigosilvabrito at hotmail.com
Tue Nov 25 14:40:43 EST 2008
Mono DataGridView no work as expected! Return NULL DataBoundItem. In Mono
2.0.1!
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 virtual decimal Reduce
{
get { return reduce; }
set { reduce = value; }
}
}
}
Designer
namespace DataGridViewProblem
{
partial class frmDataGridProblem
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// true if managed resources should be disposed; otherwise, false.
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
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.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;
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, 24);
this.dgvList.MultiSelect = false;
this.dgvList.Name = "dgvList";
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(751, 463);
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(751, 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(751, 487);
this.Controls.Add(this.dgvList);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "frmDataGridProblem";
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;
}
}
--
View this message in context: http://www.nabble.com/DataGridView-DataBoundItem-return-NULL-tp20688227p20688227.html
Sent from the Mono - WinForms mailing list archive at Nabble.com.
More information about the Mono-winforms-list
mailing list