Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a solution with two projects. The main project is a Windows Forms Application and the second project is a Windows Control Library. The goal is to use the custom datagrid created in the windows Control Library in the Windows Forms Application and have it show up in the Toolbox for that project.

 

In the Windows Control Library project, I have declared my derived DataGrid, created some properties, and overridden the OnMouseDown event. Here is my class declaration:

public class CymiGrid : System.Windows.Forms.DataGrid

My new CymiGrid builds without error, but I'm unsure of the next step. I have added it to the Windows Application as a Projects Reference, but that doesn't get it in the Toolbox.

 

I haven't used any objects from the Toolbox in my custom Control Library, not even a DataGrid. Is that what I need to do?

 

Any help is greatly appreciated.

Never ascribe to malice that which is adequately explained by incompetence. - Napoleon Bonaparte
Posted

Right-clic in the tool box and select "Add/remove items...".

 

Under ".NET Framework components" clic on "Browse..." and find your WCL dll (Windows Control Library). And now here it is!

 

Make sure that when you do a change to your WCL project to Rebuild to make sure that your Windows App will recopy the right version of your DLL.

 

Have fun !

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted
Make sure that when you do a change to your WCL project to Rebuild to make sure that your Windows App will recopy the right version of your DLL.

Thanks! That worked!

 

Regarding your word of warning, after making changes and rebuilding my custom control, do I simply remove the Reference from my Windows Application and re-add the Reference to get the new changes?

 

Thanks again.

Never ascribe to malice that which is adequately explained by incompetence. - Napoleon Bonaparte
Posted

No. Only select Rebuild instead of Build.

 

Rebuild will force your project to get the new version of each reference and DLL used by your project while build will only change modifications to your code. That's a good resume.

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

Disabling DataGrid Sorting & Project Rebuilding...

 

I'm having one last problem and rebuilding doesn't seem to be handling the changes. My custom datagrid allows the user to select columns. However, when the user Left-Clicks the column header, the column is selected as desired, but it is also Sorted; an undesired effect.

 

So, I modified my CustomGrid class project like so:

 

public class CustomGrid : System.Windows.Forms.DataGrid
{
  private System.ComponentModel.Container components = null;
  private ArrayList _selectedColumns;

  public CustomGrid()
  {
     InitializeComponent();

     [color=Blue]this[/color].AllowSorting = [color=Blue]false[/color];
     _selectedColumns = new ArrayList();
  }
}

 

I selected Rebuild from the Build menu in my CustomGrid project, then selected Rebuild from the Build menu of my TestWindowsApplication, but the sorting still occurs.

 

Any help would be greatly appreciated.

Never ascribe to malice that which is adequately explained by incompetence. - Napoleon Bonaparte
Posted

If you have TableStyles and that one in them allow sorting... well... it will allow sorting.

 

You have to remember that TableStyles have priority over "normal" Properties.

 

Tell us more... if you need. :)

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

TableStyles

 

TableStyles was exactly the problem. The more work I do on this custom datagrid, the deeper the water. Now I am beginning to question what code is appropriate in a windows control library and what should remain on the user-interface (Form1).

 

Here is my code to disable the sorting:

public class CustomGrid : System.Windows.Forms.DataGrid
{
 private System.ComponentModel.Container components = null;
 [color=Blue]private[/color] CurrencyManager cm = (CurrencyManager) [color=Blue]this[/color].BindingContext|[color=Blue]this[/color].DataSource|;
 [color=Blue]private[/color] DataGridTableStyle dgts = [color=Blue]new[/color] DataGridTableStyle(cm);
 private ArrayList _selectedColumns;

 public CustomGrid()
 {
   InitializeComponent();

   [color=Blue]this[/color].dgts.AllowSorting = [color=Blue]false[/color];
   _selectedColumns = new ArrayList();
 }
}

This control uses ColumnStyles to paint the selected columns. Therefore, this custom control will always use TableStyles and a CurrencyManager. I want this control to self-contain all the code needed for the core functionality of column-selection. The CustomColumnStyle is actually part of the class in the same namespace, but is not a nested class in the CustomGrid.

Never ascribe to malice that which is adequately explained by incompetence. - Napoleon Bonaparte
Posted
Actually, that code doesn't even build. So, that answers my question as to it's appropriateness.
Never ascribe to malice that which is adequately explained by incompetence. - Napoleon Bonaparte

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...