|
/*
* Copyright � 2005-2006 Danilo Mendez <danilo.mendez@kontac.net>
* Adolfo Socorro <ajs@esolutionspr.com>
* www.kontac.net
* All rights reserved.
* Released under both BSD license and Lesser GPL library license.
* Whenever there is any discrepancy between the two licenses,
* the BSD license will take precedence.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing.Design;
using System.ComponentModel;
using System.Windows.Forms.Design;
using System.Windows.Forms;
using SmartCode.Model.Profile;
using SmartCode.Model;
namespace SmartCode.Studio.Controls.EditorWrapper
{
class LOVEditor : UITypeEditor
{
private IWindowsFormsEditorService edSvc;
private string selectedColumns;
System.Windows.Forms.ListView uiListView;
public override UITypeEditorEditStyle
GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider, object value)
{
edSvc = provider.GetService(typeof(IWindowsFormsEditorService)) as
IWindowsFormsEditorService;
ReferenceJoinPropertyWrapper joinWrapper = context.Instance as ReferenceJoinPropertyWrapper;
ColumnPropertyWrapper columnWrapper = context.Instance as ColumnPropertyWrapper;
uiListView = new System.Windows.Forms.ListView();
uiListView.View = View.List;
uiListView.CheckBoxes = true;
uiListView.BorderStyle = BorderStyle.None;
if (edSvc != null && joinWrapper != null)
{
string[] currentValues = joinWrapper.LOV.Split(',');
Reference parentReference = joinWrapper.CurrentReferenceJoin.ParentReference;
foreach (Column column in parentReference.ParentTable.AllColumns())
{
ListViewItem li = new ListViewItem(column.Name);
li.Tag = column;
uiListView.Items.Add(li);
foreach (string s in currentValues)
{
if (s == column.Name)
{
li.Checked = true;
break;
}
}
}
}
else if (edSvc != null && columnWrapper != null)
{
string[] currentValues = columnWrapper.LOV.Split(',');
foreach (Reference parentReference in columnWrapper.CurrentColumn.Table.InReferences)
{
foreach (ReferenceJoin join in parentReference.Joins)
{
if (join.ChildColumn == columnWrapper.CurrentColumn)
{
foreach (Column column in parentReference.ParentTable.AllColumns())
{
ListViewItem li = new ListViewItem(column.Name);
li.Tag = column;
uiListView.Items.Add(li);
foreach (string s in currentValues)
{
if (s == column.Name)
{
li.Checked = true;
break;
}
}
}
}
}
}
}
uiListView.Leave += new EventHandler(listBox_Leave);
//listBox.close += new EventHandler(this.TextChanged);
this.edSvc.DropDownControl(uiListView);
return string.IsNullOrEmpty(selectedColumns) ? "" : selectedColumns.Substring(0, selectedColumns.Length - 1);
}
void listBox_Leave(object sender, EventArgs e)
{
if (this.edSvc != null)
{
selectedColumns = "";
foreach (ListViewItem li in uiListView.CheckedItems)
{
Column parentColumn = li.Tag as Column;
if (parentColumn != null)
{
selectedColumns += parentColumn.Name + ",";
}
}
this.edSvc.CloseDropDown();
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
Danilo is the creator of
SmartRules, a Business Rules Engine. He is an industry consultant working primarily with companies interested in implementing dynamic rules programming concepts to add flexibility to their architectures on web, CE, and desktop platforms. He operates his own website,
Kontac, where you will find more information.
To contact Danilo, email him at danilo.mendez@gmail.com.