TheSwamp
Code Red => .NET => Topic started 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.
-
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.
-
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?
-
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.
-
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.
Public MyDataGridView As Autodesk.AutoCAD.Windows.PaletteSet = _
New PaletteSet("DataGridView", New Guid("676900AF-16FC-43b2-931E-715DD8F96460"))
<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.
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
-
How and where is dgv declared?
-
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
-
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
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) :-)
-
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
-
You could have also just added a property or two to the class