.NET

Reply
Mentor
SRSDS
Posts: 247
Registered: ‎04-15-2011
Message 1 of 5 (289 Views)

DataGridView Lostfocus

289 Views, 4 Replies
05-16-2013 02:54 PM

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.

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 2 of 5 (276 Views)

Re: DataGridView Lostfocus

05-16-2013 08:44 PM in reply to: SRSDS

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.

 

 

 

Mentor
SRSDS
Posts: 247
Registered: ‎04-15-2011
Message 3 of 5 (268 Views)

Re: DataGridView Lostfocus

05-16-2013 09:34 PM in reply to: DiningPhilosopher

Thanks D

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?

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 4 of 5 (240 Views)

Re: DataGridView Lostfocus

05-18-2013 04:26 PM in reply to: SRSDS

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

 

Mentor
SRSDS
Posts: 247
Registered: ‎04-15-2011
Message 5 of 5 (222 Views)

Re: DataGridView Lostfocus

05-19-2013 06:40 AM in reply to: DiningPhilosopher

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.

Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.