Hi,
I have a Datagridview in a pallete that is editable.
If the user doesn't press enter after changing the cell and moves the mouse to the drawing there are two problems.
1) The input doesn't get recognized
2) The cell becomes locked. Passing values into the cell won't occur until I go back into the cell and press enter. This seems to unlock it's frozen state.
I can't find an eventhandler that recogizes that the datagridview has lost focus.
Really hoping there's a solution here. Hope someone can help.
First, if you are using the PaletteSet class directly, you need to change that to use a class that you derive from the PaletteSet.
About the focus problem, if the current control on your palette allows the user to type something (e.g., a TextBox, or a cell in a DataGridView, or some other type of control that is editable in the same way), you can't allow AutoCAD to take the focus away from your PaletteSet while the control is active or being edited.
In your derived class, override the virtual KeepFocus property, and return true if the user is editing a cell in your DataGridView, or false otherwise:
public class MyPaletteSet : PaletteSet { public override bool KeepFocus { get { return myDataGridView.IsCurrentCellInEditMode; } } }
When KeepFocus is true, AutoCAD does not take the focus away from the PaletteSet.
Glad there's a solution. I think I'm going to struggle apply it with my knowledge.
Just found this which is a minor help. http://msdn.microsoft.com/en-us/library/0wcc7ds7(v=vs.80).aspx
When I put your code below the Base class I get a few errors.
Public Class MyPaletteSet
Class 'Detail.Palette' must declare a 'Sub New" because it's base class Autodesk.Autocad.Windows.PaletteSet' dies not have an accessible 'Sub New' that can be called with no arguements.
KeepFocus has an error saying something about differing from Boolean as they differ by ReadOnly and WriteOnly
Would anyone have a skeleton piece of code so I can understand the format of deriving this class and where to move my original code?
It's going to be difficult to get very far in .NET development without the prerequisites, including things like defining classes that are derived from other classes, calling methods of the a base class, overriding virtual methods, etc., so you should probably plan on spending some time becoming more familiar with those things.
In this case, the errors are because the base class has a constructor that requires arguments, and your derived class is not calling it and providing the arguments.
You have to declare a constructor that calls the constructor of the base class and passes it the arguments it requires, like this:
Public Sub New(ByVal showCommand As String, ByVal guid As Guid) MyBase.New(showCommand, guid) ' TODO: Add initialization code here End Sub
Only the 'Get' method of the KeepFocus property can be overridden, so you have to override it using the ReadOnly keyword, like this:
Public Overrides ReadOnly Property KeepFocus As Boolean Get ' TODO: Return value appropriate for current state ' of active control End Get End Property
Thanks again. I'll have to spend some time trying to piece this one together.
I have to admit I don't really understand classes to well.
Been quite a while since I posted this.
I didn't know how to do this at the time and I'm probably not that much wiser now.
I've put together the following code as best I could.
The palette loads fine but KeepFocus() doesn't get triggered so there's something wrong with it or I just have no idea what I'm doing.
DiningPhilosopher, hoping you might be around to help again.
Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.Windows Public Class PaletteClass_Base Implements IExtensionApplication Public Sub Initialize() Implements IExtensionApplication.Initialize End Sub Public Sub Terminate() Implements IExtensionApplication.Terminate End Sub Private Shared Sub ps_Load(ByVal sender As Object, ByVal e As PalettePersistEventArgs) Dim a As Double = CType(e.ConfigurationSection.ReadProperty("MyApp", 22.3), Double) End Sub Private Shared Sub ps_Save(ByVal sender As Object, ByVal e As PalettePersistEventArgs) e.ConfigurationSection.WriteProperty("MyApp", 32.3) End Sub Sub New(showCommand, guid) If ps Is Nothing Then ps = New PaletteSet(showCommand, guid) ps.Visible = True ViewContainer = New ViewTab() ps.Add("containerNAME", myContainer) End If ps.Visible = True End Sub Public Overridable ReadOnly Property KeepFocus() As Boolean Get Return ViewContainer.DGV.IsCurrentCellInEditMode End Get End Property End Class
Public Class PaletteClass_Derived Inherits PaletteClass_Base Public Sub New(ByVal showCommand As String, ByVal guid As Guid) MyBase.New(showCommand, guid) End Sub Public Overrides ReadOnly Property KeepFocus() As Boolean Get Return True End Get End Property End Class
Can't find what you're looking for? Ask the community or share your knowledge.