MyCsla on CslaContrib

MyCsla on CslaContrib

Old forum URL: forums.lhotka.net/forums/t/7560.aspx


JonnyBee posted on Wednesday, September 02, 2009

Hi folks,

I've just put MyCsla for 3.6.3 and never (also 3-6-3-N2) on the CslaContrib site. http://cslacontrib.codeplex.com

The purpose is to give a combined Best Practice and extension points where we can all contribute with utility/helper classes, validation rules, components and more.

Best Practice
As a lot of you already has done - I have added my own baseclasses with extension points for logging/trace and a small sample of how to add/alter functionality without making modifications to Csla itself.

As for usage - I prefer to add this project as part of my solution as this make it easier to extend Csla inside my app and make all my BOs inherit from these baseclasses.

Also included are:
Validation Rules
Custom Windows Controls
And a sample app that demonstrates the custom windows controls.

The namespace is simply MyCsla and uses the same folder names as Csla. To download the code goto the Source Code tab and select Download.

I am posting this message on both the Csla.Net dicussions and CslaContrib discussion. Please post reponses concerning code/submissions in the CslaContrib forum.

I have volunteered to step up as overall coordinator of the CslaContrip and hope that we can tune up on more activity in this project. If you want to share som code/classes please join codeplex and send me info (as per home page on the project) or send me email with info about your code and I can post it.

Pleas note: The CslaContrib project uses the Creative Commons Attribution 2.5 license.

Hope you find this useful and want to contribute more code.

/jonnybee


tiago replied on Wednesday, September 02, 2009

Hi Jommybee,

I just read your message and didn't have time to look at your work. Csla is great but controls make everything so much easier...

I'm working on a Csla control:
CslaComboBox
[Description("Csla NVL ready ComboBox.")]
Requirements:
- proper ReadOnly state
- bind to master object and to Csla NVL
- Csla NVL using key of int32 and value of string (for id to description/name conversion and back)
New properties
public bool ReadOnly
public BindingSource MasterBindingSource
public Csla.NameValueListBase<Int32, String> CslaNameValueList

Are you working on something like that?

JonnyBee replied on Thursday, September 03, 2009

Hi Tiago,

Is it a Windows Forms control you are working on?

Standard ComboBox supports nearly all your requirements:
Use the ComboxTasks on the ComboBox to just get to these values for databound mode.

And use the Csla.Windows.ReadWriteAuthorizationManager to control whether combobox will be disabled/enabled based upon if user does not have permission to read/change the property. RWA asks the BO methods CanWriteProperty and CanReadProperty.

No, I am not working on a control like this - standard ComboBox works fine for my apps in databound mode.

See here too:
http://windowsclient.net/blogs/faqs/archive/2006/07/12/what-are-the-displaymember-and-valuemember.aspx  and I also highly recommend reading the DataBinding FAQ and DataGridView FAQ

/jonnybee



reagan123 replied on Thursday, September 03, 2009

Thanks for doing this.  I look forward to giving it a shot and seeing what all is available.

Thanks again.

tiago replied on Friday, September 04, 2009

Hi jonnybee,

I'm talking about WinForms controls.

Unfortunately ComboBox control has no ReadOnly property. There are a lot of solutions like having a TextBox on the same position and sizer and display it as ReadOnly when you want a ReadOnly ComboBox.

Why do I want a CslaNvlComboBox?

I read an int property from the database but I want to display the user name on the UI, on a ComboBox. So I make a BindingSource where the ID is the key and the Name is the value. Next I use a couple of events to convert from ID to Name and back like this:

...
// add a DataBinding to Sender
SenderNVLBindingSource.DataSource = UserNVL.GetUserNVL();
var senderBinding = new Binding("Text", DocBindingSource, "SenderID", true);
senderBinding.Format += OnUserFieldFormat;
senderBinding.Parse += OnUserFieldParse;
SenderComboBox.DataBindings.Add(senderBinding);
...

private void OnUserFieldParse(object sender, ConvertEventArgs e)
{
   var newUserID = UserNVL.GetUserNVL().Key(e.Value.ToString());
   if (newUserID != 0)
   {
      e.Value = newUserID;
      return;
   }
   try
   {
      if (!string.IsNullOrEmpty(UserNVL.GetUserNVL().Value(Convert.ToInt32(e.Value))))
      {
         e.Value = e.Value.ToString();
         return;
      }
   }
   catch (FormatException ex)
   {
   }
   throw new Exception("Invalid input: " + e.Value);
}

private void OnUserFieldFormat(object sender, ConvertEventArgs e)
{
   e.Value = UserNVL.GetUserNVL().Value((int)e.Value);
}

The problem is that I don't want't to write the same code over and over again for every ComboBox on the form (and there can be quite a few...).

That's why I want a control that does all this work for me.

 

JonnyBee replied on Sunday, September 06, 2009

Hi,

The ComboBox does link to/from an ID with databinding. And set DropDownStyle to ComboBoxStyle.DropDownList and AutoCompletMode to Suggest to give the user autcompletion on valid items int the list only.

I guess you could make a subclass of ComboBox that just accepts default databinding with a ReadOnly property and override the IsInputKey method and KeyDown event to make the control not accept any editing.

/jonnybee

Copyright (c) Marimer LLC