Author Topic: Access to a UserControl  (Read 2129 times)

0 Members and 1 Guest are viewing this topic.

hellios8502

  • Guest
Access to a UserControl
« 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.


mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Access to a UserControl
« Reply #1 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.
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

hellios8502

  • Guest
Re: Access to a UserControl
« Reply #2 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?

jgr

  • Guest
Re: Access to a UserControl
« Reply #3 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.

hellios8502

  • Guest
Re: Access to a UserControl
« Reply #4 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
« Last Edit: March 24, 2011, 06:37:37 PM by Kerry »

Jeff H

  • Needs a day job
  • Posts: 6103
Re: Access to a UserControl
« Reply #5 on: March 24, 2011, 06:39:02 PM »
How and where is dgv declared?


jgr

  • Guest
Re: Access to a UserControl
« Reply #6 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
« Last Edit: March 24, 2011, 07:10:33 PM by jgr »

hellios8502

  • Guest
Re: Access to a UserControl
« Reply #7 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) :-)

hellios8502

  • Guest
Re: Access to a UserControl
« Reply #8 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

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16872
  • Superior Stupidity at its best
Re: Access to a UserControl
« Reply #9 on: March 29, 2011, 04:13:36 AM »
You could have also just added a property or two to the class
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie