Solved

DataGridTableStyles problem Another one

Posted on 2004-09-25
3
183 Views
Last Modified: 2010-04-23
I am using the RustemSoft.DataGridColumns to create a combobox inside datagrid.

here is the code.  my problem follows

--------------------------------------
Imports RustemSoft.DataGridColumns
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents DaAccess As System.Data.OleDb.OleDbDataAdapter
    Friend WithEvents OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand
    Friend WithEvents OleDbInsertCommand1 As System.Data.OleDb.OleDbCommand
    Friend WithEvents OleDbUpdateCommand1 As System.Data.OleDb.OleDbCommand
    Friend WithEvents OleDbDeleteCommand1 As System.Data.OleDb.OleDbCommand
    Friend WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection
    Friend WithEvents DataSet11 As dataGridStyle_Project.DataSet1
    Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.DaAccess = New System.Data.OleDb.OleDbDataAdapter
        Me.OleDbDeleteCommand1 = New System.Data.OleDb.OleDbCommand
        Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
        Me.OleDbInsertCommand1 = New System.Data.OleDb.OleDbCommand
        Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand
        Me.OleDbUpdateCommand1 = New System.Data.OleDb.OleDbCommand
        Me.DataSet11 = New dataGridStyle_Project.DataSet1
        Me.DataGrid1 = New System.Windows.Forms.DataGrid
        CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'DaAccess
        '
        Me.DaAccess.DeleteCommand = Me.OleDbDeleteCommand1
        Me.DaAccess.InsertCommand = Me.OleDbInsertCommand1
        Me.DaAccess.SelectCommand = Me.OleDbSelectCommand1
        Me.DaAccess.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Accessorie", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("Access_Desc", "Access_Desc"), New System.Data.Common.DataColumnMapping("Access_Type", "Access_Type"), New System.Data.Common.DataColumnMapping("Accessorie_ID", "Accessorie_ID"), New System.Data.Common.DataColumnMapping("R_List_Price", "R_List_Price")})})
        Me.DaAccess.UpdateCommand = Me.OleDbUpdateCommand1
        '
        'OleDbDeleteCommand1
        '
        Me.OleDbDeleteCommand1.CommandText = "DELETE FROM Accessorie WHERE (Accessorie_ID = ?) AND (R_List_Price = ? OR ? IS NU" & _
        "LL AND R_List_Price IS NULL)"
        Me.OleDbDeleteCommand1.Connection = Me.OleDbConnection1
        Me.OleDbDeleteCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Accessorie_ID", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Accessorie_ID", System.Data.DataRowVersion.Original, Nothing))
        Me.OleDbDeleteCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_R_List_Price", System.Data.OleDb.OleDbType.Currency, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "R_List_Price", System.Data.DataRowVersion.Original, Nothing))
        Me.OleDbDeleteCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_R_List_Price1", System.Data.OleDb.OleDbType.Currency, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "R_List_Price", System.Data.DataRowVersion.Original, Nothing))
        '
        'OleDbConnection1
        '
        Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
        "ocking Mode=0;Data Source=""C:\Documents and Settings\user\My Documents\Quote-a-m" & _
        "atic2000\Database\AltoDatabase.mdb"";Jet OLEDB:Engine Type=5;Provider=""Microsoft." & _
        "Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security i" & _
        "nfo=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=F" & _
        "alse;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compa" & _
        "ct=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:" & _
        "Global Bulk Transactions=1"
        '
        'OleDbInsertCommand1
        '
        Me.OleDbInsertCommand1.CommandText = "INSERT INTO Accessorie(Access_Desc, Access_Type, Accessorie_ID, R_List_Price) VAL" & _
        "UES (?, ?, ?, ?)"
        Me.OleDbInsertCommand1.Connection = Me.OleDbConnection1
        Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Access_Desc", System.Data.OleDb.OleDbType.VarWChar, 0, "Access_Desc"))
        Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Access_Type", System.Data.OleDb.OleDbType.VarWChar, 0, "Access_Type"))
        Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Accessorie_ID", System.Data.OleDb.OleDbType.VarWChar, 50, "Accessorie_ID"))
        Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("R_List_Price", System.Data.OleDb.OleDbType.Currency, 0, "R_List_Price"))
        '
        'OleDbSelectCommand1
        '
        Me.OleDbSelectCommand1.CommandText = "SELECT Access_Desc, Access_Type, Accessorie_ID, R_List_Price FROM Accessorie"
        Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1
        '
        'OleDbUpdateCommand1
        '
        Me.OleDbUpdateCommand1.CommandText = "UPDATE Accessorie SET Access_Desc = ?, Access_Type = ?, Accessorie_ID = ?, R_List" & _
        "_Price = ? WHERE (Accessorie_ID = ?) AND (R_List_Price = ? OR ? IS NULL AND R_Li" & _
        "st_Price IS NULL)"
        Me.OleDbUpdateCommand1.Connection = Me.OleDbConnection1
        Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Access_Desc", System.Data.OleDb.OleDbType.VarWChar, 0, "Access_Desc"))
        Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Access_Type", System.Data.OleDb.OleDbType.VarWChar, 0, "Access_Type"))
        Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Accessorie_ID", System.Data.OleDb.OleDbType.VarWChar, 50, "Accessorie_ID"))
        Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("R_List_Price", System.Data.OleDb.OleDbType.Currency, 0, "R_List_Price"))
        Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_Accessorie_ID", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Accessorie_ID", System.Data.DataRowVersion.Original, Nothing))
        Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_R_List_Price", System.Data.OleDb.OleDbType.Currency, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "R_List_Price", System.Data.DataRowVersion.Original, Nothing))
        Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_R_List_Price1", System.Data.OleDb.OleDbType.Currency, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "R_List_Price", System.Data.DataRowVersion.Original, Nothing))
        '
        'DataSet11
        '
        Me.DataSet11.DataSetName = "DataSet1"
        Me.DataSet11.Locale = New System.Globalization.CultureInfo("en-NZ")
        '
        'DataGrid1
        '
        Me.DataGrid1.DataMember = ""
        Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid1.Location = New System.Drawing.Point(32, 48)
        Me.DataGrid1.Name = "DataGrid1"
        Me.DataGrid1.Size = New System.Drawing.Size(584, 208)
        Me.DataGrid1.TabIndex = 0
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(648, 273)
        Me.Controls.Add(Me.DataGrid1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'fill the dataset
        Me.DaAccess.Fill(Me.DataSet11)
        Try
        'set the datagrid setting
        With DataGrid1
            ' Set DataGrid Data Binding to Cars table
            .SetDataBinding(DataSet11, "Accessorie")
            ' Set DataGrid Background Color
            .BackgroundColor = System.Drawing.Color.Lavender
            ' Set DataGrid Caption Background Color
            .CaptionBackColor = System.Drawing.Color.SlateBlue
            ' Set DataGrid Caption Foreground Color
            .CaptionForeColor = System.Drawing.Color.LemonChiffon
            ' Set DataGrid Parent Rows Background Color
            .ParentRowsBackColor = System.Drawing.Color.Lavender
            ' Set DataGrid Parent Rows Foreground Color
            .ParentRowsForeColor = System.Drawing.Color.SlateBlue
            ' Set DataGrid Caption Text
            .CaptionText = "Accessories"
            ' Clear DataGrid Table Styles
            .TableStyles.Clear()
        End With

        Dim tblCrrncMngr As CurrencyManager = CType(BindingContext(DataSet11.Tables.Item("Accessorie")), CurrencyManager)
        Dim TblStyle As New DataGridTableStyle
        With TblStyle
            .MappingName = "Cars"
            .BackColor = System.Drawing.Color.White
            .ForeColor = System.Drawing.Color.DarkSlateBlue
            .GridLineColor = System.Drawing.Color.MediumSlateBlue
            .HeaderBackColor = System.Drawing.Color.Lavender
            .HeaderForeColor = System.Drawing.Color.MediumSlateBlue
            .AlternatingBackColor = Color.LightGray
            .RowHeaderWidth = 10

            ' Set column styles
            With .GridColumnStyles
                ' Set datagrid ColumnStyle for Accesssory ID field
                .Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("Accssorie_ID")))
                With .Item(0)
                    .MappingName = "Accssorie_ID")))"
                    .HeaderText = "Accssory" ))"
                    .Width = 100
                    .NullText = String.Empty
                End With

                ' Set datagrid ComboBox ColumnStyle for PubID field
                .Add(New DataGridComboBoxColumn(DataSet11.Tables.Item("Access_Type"), 1, 0))
                ' Datagrid ComboBox DisplayMember field has order number 1. Name of this column is "Name"
                ' Datagrid ComboBox ValueMember field has order number 0. Name of this column is "PubID"
                With .Item(1)
                    .MappingName = "Access_Type"
                    .HeaderText = "Access Type"
                    .Width = 180
                    .NullText = String.Empty
                End With


                ' Set datagrid Memo ColumnStyle for description field
                .Add(New DataGridMemoColumn("Access_Desc"))
                With .Item(5)
                    .MappingName = "Access_Desc"
                    .HeaderText = "Description"
                    .Width = 90
                    .NullText = String.Empty
                End With
            End With
        End With
        'assig the table style to the datagrid table styles
        DataGrid1.TableStyles.Add(TblStyle)

        Catch ex As Exception
            MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop)
            'cn.Close()
            DaAccess.Dispose()
            Me.Close()
        End Try

    End Sub
End Class
---------------------------------------------

Add(New DataGridTextBoxColumn(tblCrrncMngr.GetItemProperties.Item("Accssorie_ID")))

on this line i get this error

"object reference not set to an instance of an object"

I have been getting this problem in a few different places, if any one could help me by showing me how to use a debug tool to solve this that would be great.


0
Comment
Question by:Nerdy_Girl88
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
J_Mak earned 500 total points
ID: 12157734
Ok, you are getting that error because some variable has not been initialised properly. That is, one of your object referencees (such as a variable) is set to null or nothing. To debug, place a breakpoint at this line and and then run the application. When it breaks at this line, place your mouse arrow over the "tblCrrncMngr" variable. I'm assuming that this may not be initialised. What does it say when you put your mouse over it? Does it say "Nothing"?

If it says "Nothing", then just by back-tracking, you may not have initialised other object references on which "tblCrrncMngr" depends upon. Although it seems that "tblCrrncMngr" is not initialised, it could however be DataSet11 (which may not have been filled properly). However, you may have to backtrack its initialisation process and see where it has gone wrong.

Also, while it is debugging (and before it hits the breakpoint), you could right click on "tblCrrncMngr" and select "quickwatch" on the context menu to view its state while debugging. This is a very helpful tool. You can also apply a quickwatch on DataSet11. I'm assuming that it may not have been filled properly. Hope that helps!
0
 

Author Comment

by:Nerdy_Girl88
ID: 12224495
Sorry for the long reply but i have been trying a few things out.

Your right for some reason i Wasn't initailising my variable, i have since moved on,  I am loving the use of this watch feature,  Thanks  for the tip.

Nerdy_Girl
0
 
LVL 7

Expert Comment

by:J_Mak
ID: 12224580
No worries, I'm glad I could help!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now