473,396 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Additional information: Object reference not set to an instance of an object.

I get this message in "Spaltenbreite definieren" => Definition for Columns
Width

An unhandled exception of type 'System.NullReferenceException' occurred in
WindowsApplication1.exe

Additional information: Object reference not set to an instance of an
object.

Please help me.

Thanks

Michael

CODE:
=====
private void CreateMyDatagrid()

{

// MyDatagrid erstellen

DataGrid MyDataGrid = new DataGrid();

MyDataGrid.Bounds = new Rectangle(new Point(10,10), new Size(650,350));

// Datagrid Eigenschaften

MyDataGrid.CaptionText="Berechtigung -> ALLE = A+B+E+L / A=Ansehen /
B=Bearbeiten / E = Erstellen / L=Löschen";

MyDataGrid.ReadOnly = false;

// Dataset erstellen

DataSet MyDataSet = new DataSet();
DataGridTableStyle myTableStyle = new DataGridTableStyle();

myTableStyle.MappingName = "MappingName_ts_berechtigung"; // ts=tablestyle

DataGridBoolColumn boolCol = new DataGridBoolColumn();

boolCol.MappingName="MappingName_dgbc_berechtigung ";
//dgbc=datagridboolcolumn

((DataGridBoolColumn)boolCol).AllowNull = false;

myTableStyle.GridColumnStyles.Add(boolCol);

//MyDataGrid.TableStyles.Clear();

// DataTable erstellen

DataTable dt = new DataTable("DataTable_Berechtigung");
// Spalten erstellen

dt.Columns.Add("Modul", typeof(string)).ReadOnly = true;

dt.Columns.Add("Zusatz...", typeof(string)).ReadOnly = true;

dt.Columns.Add("ALLE", typeof(bool));

dt.Columns.Add("A", typeof(bool));

dt.Columns.Add("B", typeof(bool));

dt.Columns.Add("E", typeof(bool));

dt.Columns.Add("L", typeof(bool));

//Spaltenbreite definieren

myTableStyle.GridColumnStyles["Modul"].Width=20;

myTableStyle.GridColumnStyles["Zusatz..."].Width=50;

myTableStyle.GridColumnStyles["ALLE"].Width=60;

//MyDataGrid.TableStyles["DataTable_Berechtigung"].GridColumnStyles[0].Width
=0;

//MyDataGrid.TableStyles["DataTable_Berechtigung"].GridColumnStyles[1].Width
=80;

//MyDataGrid.TableStyles["DataTable_Berechtigung"].GridColumnStyles[2].Width
=80;

//MyDataGrid.TableStyles["DataTable_Berechtigung"].GridColumnStyles[3].Width
=20;

// Zeilen erstellen und inhalt abfüllen

// checkbox in variable

int test = 1;

dt.Rows.Add(new Object[] {"Adresse", "ev. sonst noch was",0,test,0,0,0});

dt.Rows.Add(new Object[] {"Depositen", "ev. sonst noch was",1,1,1,1,1});

dt.Rows.Add(new Object[] {"Obligation", "ev. sonst noch was",0,0,0,0,0});

dt.Rows.Add(new Object[] {"Miete", "ev. sonst noch was",1,1,1,1,1});

dt.Rows.Add(new Object[] {"Stammdaten", "ev. sonst noch was",0,0,0,0,0});

// DataTable in dataset

MyDataSet.Tables.Add(dt);
// Dataset in datagrid

MyDataGrid.SetDataBinding(MyDataSet,"DataTable_Ber echtigung");

// Tablestyle dem Datagrid hinzufügen

MyDataGrid.TableStyles.Add(myTableStyle);
// Anzeigen des Datagrids

this.Controls.Add(MyDataGrid);

}
Nov 16 '05 #1
4 5951
"michael walser" <mi************@bingo.de> wrote in
news:eZ*************@TK2MSFTNGP12.phx.gbl:
I get this message in "Spaltenbreite definieren" => Definition for
Columns Width

An unhandled exception of type 'System.NullReferenceException' occurred
in WindowsApplication1.exe

Additional information: Object reference not set to an instance of an
object.

Please help me.
// Spalten erstellen

dt.Columns.Add("Modul", typeof(string)).ReadOnly = true;
dt.Columns.Add("Zusatz...", typeof(string)).ReadOnly = true;
dt.Columns.Add("ALLE", typeof(bool)); .... //Spaltenbreite definieren

myTableStyle.GridColumnStyles["Modul"].Width=20;
myTableStyle.GridColumnStyles["Zusatz..."].Width=50;
myTableStyle.GridColumnStyles["ALLE"].Width=60;


In the debugger, could you please check if these column styles are
actually defined? You probably should add a new GridColumnStyle first.

Frans.

--
Get LLBLGen Pro, the new O/R mapper for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP
Nov 16 '05 #2
Frans Bouma [C# MVP] wrote:
"michael walser" <mi************@bingo.de> wrote in
news:eZ*************@TK2MSFTNGP12.phx.gbl:

I get this message in "Spaltenbreite definieren" => Definition for
Columns Width

An unhandled exception of type 'System.NullReferenceException' occurred
in WindowsApplication1.exe

Additional information: Object reference not set to an instance of an
object.

Please help me.
// Spalten erstellen

dt.Columns.Add("Modul", typeof(string)).ReadOnly = true;
dt.Columns.Add("Zusatz...", typeof(string)).ReadOnly = true;
dt.Columns.Add("ALLE", typeof(bool));


...
//Spaltenbreite definieren

myTableStyle.GridColumnStyles["Modul"].Width=20;
myTableStyle.GridColumnStyles["Zusatz..."].Width=50;
myTableStyle.GridColumnStyles["ALLE"].Width=60;

In the debugger, could you please check if these column styles are
actually defined? You probably should add a new GridColumnStyle first.

Frans.

Yes? that's right. I met with this error many time.
Nov 16 '05 #3
Frans Bouma [C# MVP] wrote:
"michael walser" <mi************@bingo.de> wrote in
news:eZ*************@TK2MSFTNGP12.phx.gbl:

I get this message in "Spaltenbreite definieren" => Definition for
Columns Width

An unhandled exception of type 'System.NullReferenceException' occurred
in WindowsApplication1.exe

Additional information: Object reference not set to an instance of an
object.

Please help me.
// Spalten erstellen

dt.Columns.Add("Modul", typeof(string)).ReadOnly = true;
dt.Columns.Add("Zusatz...", typeof(string)).ReadOnly = true;
dt.Columns.Add("ALLE", typeof(bool));


...
//Spaltenbreite definieren

myTableStyle.GridColumnStyles["Modul"].Width=20;
myTableStyle.GridColumnStyles["Zusatz..."].Width=50;
myTableStyle.GridColumnStyles["ALLE"].Width=60;

In the debugger, could you please check if these column styles are
actually defined? You probably should add a new GridColumnStyle first.

Frans.

Yes, that's right. I met with this error many time.
Nov 16 '05 #4
Yes it works.

// Tablestyle erstellen

DataGridTableStyle myTableStyle = new DataGridTableStyle();

myTableStyle.MappingName = "DataTable_Berechtigung";

MyDataGrid.TableStyles.Clear();
// Spalten-Eigenschaften

DataGridTextBoxColumn Col_0 = new DataGridTextBoxColumn();

Col_0.MappingName="Modul";

Col_0.Width = 150;

Col_0.ReadOnly = true;

Col_0.HeaderText = "Module";

DataGridBoolColumn Col_1 = new DataGridBoolColumn();

Col_1.MappingName="ALLE";

Col_1.Width = 60;

Col_1.AllowNull = false;

Col_1.HeaderText = "ALLE";

Col_1.Alignment = System.Windows.Forms.HorizontalAlignment.Center;

DataGridBoolColumn Col_2 = new DataGridBoolColumn();

......etc etc..

Thanks for your help

Michael
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: michael walser | last post by:
I get this message in "Spaltenbreite definieren" => Definition for Columns Width An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication1.exe Additional...
6
by: Christopher Young | last post by:
I have several user controls on a page and I am trying to get information out of them. The postback is being caused on the aspx page and not in the user control. I have tried using a property but...
2
by: Brad | last post by:
Receive the following error when stepping into the FILL (see last line). Being a newbie I cannot see anything obvious. Error message: An unhandled exception of type...
4
by: Supra | last post by:
I am doing irc chat similar to mirc chat if i connected to irc.webamster.com i had no problem. but if connected to eu.undernet.org. i got error....somthing bug me! O:-) 'February 2004 'An...
1
by: Supra | last post by:
'An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll 'Additional information: Object reference not set to an instance of an object. in module: Dim...
12
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. ...
6
by: Shailen Sukul | last post by:
Observed a weird behaviour with object references. See code listing below: using System; using System.Collections.Generic; using System.Text; namespace PointerExceptionTest { /*
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.