Datagrid and money format problems (BUG?)

T

Tamlin

Hi all,

I'm getting a bug with the datagrid object.
I've created one from scratch, bound it to a dataview with 2 int32
columns and formatted the output as currency.

I've found that when you use the F2 key to enter edit mode and then
hit TAB or ESCAPE without actually editing the value, dotnet crashes
with a null reference error.

Any takers?

To replicate this problem, create a new form, add a datagrid and add a
tablestyle with two columns, mapping to col1 and col2.
Set the format of col1 to "c" and put this in the constuctor:

DataTable loTable = new DataTable();
loTable.Columns.Add("col1", typeof(Int32));
loTable.Columns.Add("col2", typeof(Int32));

this.dataGrid1.DataSource = loTable.DefaultView;
loTable.Rows.Add(loTable.NewRow());
loTable.Rows[0]["col1"] = 1234;
loTable.Rows[0]["col2"] = 5678;

Run it, and hit F2 on the first cell, and then TAB.

I've also noticed that it won't crash if there's only one column.

Please help!


Thanks,
Tamlin Cowgill
 
C

Cor Ligthert

Tamlin,

I could not reproduce your problem. I have installed the sp1 for Net 1.1

Cor
 
T

Tamlin

It must be something else, I've just installed SP 1 for .Net FWK 1.1
this morning and I'm still getting the same problems.

Can anybody else replicate this problem?

I'm using:
Microsoft Development Environment 2003, Version 7.1.3088
Microsoft .Net Framework 1.1 Version 1.1.4322 SP1
Microsoft Windows 2000 SP4
I also had VSIP installed but have since had it removed.


Here's the entire form code:


//Cut Here: --------------------------------------------------
using System;
using System.Drawing;
using System.Collections;,
using System.Windows.Forms;
using System.Data;

namespace Products
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.DataGridTableStyle dataGridTableStyle1;
private System.Windows.Forms.DataGridTextBoxColumn
dataGridTextBoxColumn1;
private System.Windows.Forms.DataGridTextBoxColumn
dataGridTextBoxColumn2;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
DataTable loTable;
DataRow loRow;
loTable = new DataTable();
loTable.Columns.Add("col1", typeof(Int32));
loTable.Columns.Add("col2", typeof(Int32));
dataGrid1.DataSource = loTable;
loRow = loTable.NewRow();
loTable.Rows.Add(loRow);
loRow["col1"] = 1234;
loRow["col2"] = 5678;
}


/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(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()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.dataGridTableStyle1 = new
System.Windows.Forms.DataGridTableStyle();
this.dataGridTextBoxColumn1 = new
System.Windows.Forms.DataGridTextBoxColumn();
this.dataGridTextBoxColumn2 = new
System.Windows.Forms.DataGridTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor =
System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(8, 8);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(280, 264);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.TableStyles.AddRange(new
System.Windows.Forms.DataGridTableStyle[] {
this.dataGridTableStyle1});
//
// dataGridTableStyle1
//
this.dataGridTableStyle1.DataGrid = this.dataGrid1;
this.dataGridTableStyle1.GridColumnStyles.AddRange(new
System.Windows.Forms.DataGridColumnStyle[] {
this.dataGridTextBoxColumn1,
this.dataGridTextBoxColumn2});
this.dataGridTableStyle1.HeaderForeColor =
System.Drawing.SystemColors.ControlText;
this.dataGridTableStyle1.MappingName = "";
//
// dataGridTextBoxColumn1
//
this.dataGridTextBoxColumn1.Format = "c";
this.dataGridTextBoxColumn1.FormatInfo = null;
this.dataGridTextBoxColumn1.MappingName = "col1";
this.dataGridTextBoxColumn1.Width = 75;
//
// dataGridTextBoxColumn2
//
this.dataGridTextBoxColumn2.Format = "c";
this.dataGridTextBoxColumn2.FormatInfo = null;
this.dataGridTextBoxColumn2.MappingName = "col2";
this.dataGridTextBoxColumn2.Width = 75;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.dataGrid1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);

}
#endregion
}
}
// To Here:----------------------------------------------

And here's the output
Unhandled Exception: System.NullReferenceException: Object reference
not set to an instance of an object.
at System.Windows.Forms.DataGrid.CommitEdit()
at System.Windows.Forms.DataGrid.EndEdit()
at System.Windows.Forms.DataGrid.Edit(String instantText)
at System.Windows.Forms.DataGrid.Edit()
at System.Windows.Forms.DataGrid.set_CurrentCell(DataGridCell
value)
at System.Windows.Forms.DataGrid.set_CurrentColumn(Int32 value)
at System.Windows.Forms.DataGrid.ProcessTabKey(Keys keyData)
at System.Windows.Forms.DataGrid.ProcessGridKey(KeyEventArgs ke)
at System.Windows.Forms.DataGrid.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.Control.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.TextBoxBase.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
at System.Windows.Forms.ThreadContext.System.Windows.Forms.UnsafeNativeMethods+IMsoComponent.FPreTranslateMessage(MSG&
msg)
at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at Products.App.Main(String[] asArgs) in
c:\dotnet\productmigration\products\classes\app.cs:line 53The program
'[1420] Products.exe' has exited with code 0 (0x0).

Regards,
Tamlin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top