Custom control derived from DataGrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I've got a problem with creating cutom control derived from
System.Windows.Forms.DataGrid. When trying to add it to the form in design
mode, the "The object can not be converted to target type" message apears!
If i derive the control from another class, everything works properly. I
have made controls derived from TextBox, Label, ListControl with no problems.

Thanks for any advice.
Michal Rizek
 
Do you have a reference to System.Windows.Forms.DataGrid.dll in your project
(this control is separate from the main System.Windows.Forms assembly)

Peter
 
Yes.

Peter Foot said:
Do you have a reference to System.Windows.Forms.DataGrid.dll in your project
(this control is separate from the main System.Windows.Forms assembly)

Peter
 
This is the basic code of that component....

using System;

namespace BLForms
{
/// <summary>
/// Summary description for DBDataGrid.
/// </summary>
public class DBDataGrid : System.Windows.Forms.DataGrid
{
DBSource dbSource;

#if NETCFDESIGNTIME
[System.ComponentModel.Category("Data")]
[System.ComponentModel.DefaultValueAttribute(null)]
[System.ComponentModel.Description("DBSource object to be assigned with
this datagrid.")]
#endif
/// <summary>
/// Objekt DBSource ze kterého se zobrazují data.
/// </summary>
public DBSource DbSource
{
set
{
dbSource = value;
if(dbSource != null)
dbSource.Register(this);
}
get { return dbSource;}
}

public void RefreshData()
{
if( dbSource == null) return;
Visible = false;
DataSource = dbSource.GetTable();
Select(dbSource.Position);
this.Visible = true;
}

public DBDataGrid()
{
this.CurrentCellChanged += new EventHandler(OnCCellChanged);
}

protected void OnCCellChanged( object sender, EventArgs e)
{
this.Select(this.CurrentCell.RowNumber);
dbSource.Goto(this.CurrentCell.RowNumber);
}


}
}


This simple code causes same error....
public class DBDataGrid : System.Windows.Forms.DataGrid
{
DBDataGrid()
{

}
}
 
Back
Top