TheSwamp

Code Red => .NET => Topic started by: hellios8502 on March 24, 2011, 04:43:29 PM

Title: Access to a UserControl
Post by: hellios8502 on March 24, 2011, 04:43:29 PM
Hi
I have a bit of a dum question, but it's been a great headache for the last couple of days  :-o

I implemented a Palette with a DataGridView on it but I can't access the Grid control through a CommandMethod.

For example:

Private Sub Add5000RowsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Add5000RowsToolStripMenuItem.Click
        dgv.Rows.Clear()
        dgv.Columns.Clear()
        dgv.RowCount = 5000
        dgv.ColumnCount = 100
    End Sub

This adds a couple  :roll:  of rows in the grid control via a ToolStripMenu, but when I write something like:

  <CommandMethod("ccc")> _
    Public Sub cl()

do something whit the datagridview
End Sub

follows:

Error   6   Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.   

Any help would be greatly appreciated.

Thanks in advance.

Title: Re: Access to a UserControl
Post by: mohnston on March 24, 2011, 05:09:22 PM
Not a VB.NET guy but is your CommandMethod in the same class as your form?
If it is, it shouldn't be.
If it is not, then there is no datagridview to do stuff with.
Title: Re: Access to a UserControl
Post by: hellios8502 on March 24, 2011, 05:18:51 PM
Yes it is in the same class and I have other subs using CommandMethod that work just fine.
The problem is that I can't access the grid control.
For example when I try msgbox(me.DayaGridView1.rowscount) the msgbox displays nothing .

Why you think I shouldn't be using CommandMethod grom within the UserControl class?
Title: Re: Access to a UserControl
Post by: jgr on March 24, 2011, 05:59:38 PM
Error   6   Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.   
Shared..., variables at module level...?

Please, post the full code.
Title: Re: Access to a UserControl
Post by: hellios8502 on March 24, 2011, 06:29:00 PM
There is not a lot of code for posting  :oops: i have just made a palette on a user control with a datagridview on it.
Code: [Select]
Public MyDataGridView As Autodesk.AutoCAD.Windows.PaletteSet = _
   New PaletteSet("DataGridView", New Guid("676900AF-16FC-43b2-931E-715DD8F96460"))
Code: [Select]
  <CommandMethod("AddDataGridView")> _
Public Sub AddDataGridView()

        Dim TextDIS As New Palette_GridControl

        Dim cont As Boolean
        cont = False
        For i As Integer = 0 To MyDataGridView.Count - 1
            If MyDataGridView(i).Name = "DataGridView" Then
                MyDataGridView.Visible = True
                cont = True
            End If
        Next
        If cont = False Then
            MyDataGridView.Add("DataGridView", TextDIS)
        End If
        MyDataGridView.Visible = True
    End Sub
This part starts the palette, I am using more than one palette and they are defined in a separate class.
Code: [Select]
Public Class Palette_GridControl
Private Sub Add5000RowsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Add5000RowsToolStripMenuItem.Click
        dgv.Rows.Clear()
        dgv.Columns.Clear()
        dgv.RowCount = 5000
        dgv.ColumnCount = 100

    End Sub

    <CommandMethod("ccc")> _
    Public Sub cl()

        MsgBox(dgv.RowCount)----Here is the problem :?  (dgv=DaraGridView :-) such a long name)

    End Sub
End Class
This code is in the usercontroll class


edit:kdub - code tags added
Title: Re: Access to a UserControl
Post by: Jeff H on March 24, 2011, 06:39:02 PM
How and where is dgv declared?

Title: Re: Access to a UserControl
Post by: jgr on March 24, 2011, 07:01:39 PM
How and where is dgv declared?

hellios8502, Do you not undertand this???: Please post full (vs .net) project

Yes it is in the same class and I have other subs using CommandMethod that work just fine.

other subs...?

It seems you do not understand., read firt's 3 lines.
Sorry i do not speak English and did not explain better

Note:
The first paragraph is to hellios8502, but appears otherwise
Title: Re: Access to a UserControl
Post by: hellios8502 on March 25, 2011, 07:59:11 AM
Code: [Select]
Public Class Class_Palettes
    Public FileName As String
 
    Public MyDataGridView As Autodesk.AutoCAD.Windows.PaletteSet = _
   New PaletteSet("DataGridView", New Guid("676900AF-16FC-43b2-931E-715DD8F96460"))

 
    <CommandMethod("hellios")> _
   Public Sub Palette()
        If myPaletteSet.Count = 0 Then

            Dim textTools As Palette_TextTools = New Palette_TextTools

            Dim polyllineTools As Palette_PolylineTools = New Palette_PolylineTools

            Dim layoutools As Palette_Layout_Tools = New Palette_Layout_Tools


            myPaletteSet.Add("Text Tools", textTools)
            myPaletteSet.Add("Polyline Tools", polyllineTools)
            myPaletteSet.Add("Layout Tools", layoutools)
        Else : myPaletteSet.Visible = True
        End If
        myPaletteSet.Visible = True
    End Sub

 
        If cont = False Then
            MyDataGridView.Add("DataGridView", TextDIS)
        End If
        MyDataGridView.Visible = True
    End Sub

    <CommandMethod("RemoveDataGridView")> _
  Public Sub RemoveDataGridView()
        MyDataGridView(0).PaletteSet.Visible = False
    End Sub
 
End Class


Code: [Select]
Public Class Palette_GridControl
Private Sub Add5000RowsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Add5000RowsToolStripMenuItem.Click
        dgv.Rows.Clear()
        dgv.Columns.Clear()
        dgv.RowCount = 5000
        dgv.ColumnCount = 100

    End Sub


    <CommandMethod("ccc")> _
    Public Sub cl()


        MsgBox(dgv.RowCount)


    End Sub

   
End Class



With a button in the main palette set I am calling the datagridview palette on which
there is a grid control defined directly (dragged from the toolbox) :-)
Title: Re: Access to a UserControl
Post by: hellios8502 on March 26, 2011, 12:36:39 PM
I knew it was a dum question bu I asked it :-).

I solved my problem by declaring the elements I needed access to in a Module instead in the class.

Thanks again for the help
Title: Re: Access to a UserControl
Post by: Keith™ on March 29, 2011, 04:13:36 AM
You could have also just added a property or two to the class