[Mono-dev] DataGridView virtual mode, exception

Cetin Sert cetin.sert at gmail.com
Fri Apr 4 11:06:43 EDT 2008


Dear Mono Devs,

mono DGVV.exe

Unhandled Exception: System.NullReferenceException: Object reference not set
to an instance of an object
  at System.Windows.Forms.DataGridView.set_RowCount (Int32 value) [0x00000]
  at (wrapper remoting-invoke-with-check)
System.Windows.Forms.DataGridView:set_RowCount (int)
  at DGVV.Form1..ctor () [0x00000]
  at (wrapper remoting-invoke-with-check) DGVV.Form1:.ctor ()
  at DGVV.Program.Main () [0x00000]

when setting RowCount property on a DataGridView instance in virtual mode, I
get the above exception with Mono 1.2.4, 1.2.6 and 1.9.

Is virtual mode of DataGridView usable in Mono (1.9)?

If it is, what am I doing wrong?
If it is not, what other winforms grid control do you suggest me to use? (It
should have a virtual mode support... I tested SourceGrid but it does not
draw properly when in virtual mode.)

Best Regards,
Cetin Sert

http://corsis.de



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DGVV
{
    public partial class Form1 : Form
    {
        public DataGridView dgv = new DataGridView();

        public Form1()
        {
            InitializeComponent();

            dgv.VirtualMode = true;

            dgv.CellValueNeeded += new
DataGridViewCellValueEventHandler(dgv_CellValueNeeded);

            // Add columns to the DataGridView.
            DataGridViewTextBoxColumn companyNameColumn = new
DataGridViewTextBoxColumn();
            companyNameColumn.HeaderText = "Company Name";
            companyNameColumn.Name = "Company Name";
            DataGridViewTextBoxColumn contactNameColumn = new
DataGridViewTextBoxColumn();
            contactNameColumn.HeaderText = "Contact Name";
            contactNameColumn.Name = "Contact Name";
            dgv.Columns.Add(companyNameColumn);
            dgv.Columns.Add(contactNameColumn);
            dgv.AutoSizeColumnsMode =
DataGridViewAutoSizeColumnsMode.AllCells;
            dgv.EditMode = DataGridViewEditMode.EditProgrammatically;
            dgv.AllowUserToAddRows = false;

            dgv.RowCount = 4;
        }

        void dgv_CellValueNeeded(object sender,
DataGridViewCellValueEventArgs e)
        {
            switch (e.ColumnIndex)
            {
                case 0:
                    e.Value = "Sertcom";
                    break;

                case 1:
                    e.Value = e.RowIndex < 2 ? "Cetin" : "Metin";
                    break;
            }
        }
    }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080404/3f5bacf4/attachment.html 


More information about the Mono-devel-list mailing list