/
BrowseControl.cs
116 lines (103 loc) · 4.68 KB
/
BrowseControl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//===============================================================================================================
// System : EWSoftware.PDI Windows Forms Controls
// File : BrowseControl.cs
// Author : Eric Woodruff (Eric@EWoodruff.us)
// Updated : 11/23/2018
// Note : Copyright 2004-2018, Eric Woodruff, All rights reserved
// Compiler: Visual C#
//
// This is used to move forward and backward through a collection of objects. It can also add objects to and
// delete objects from the collection. Derived classes should override the virtual methods to add the required
// functionality.
//
// This code is published under the Microsoft Public License (Ms-PL). A copy of the license should be
// distributed with the code and can be found at the project website: https://github.com/EWSoftware/PDI.
// This notice, the author's name, and all copyright notices must remain intact in all applications,
// documentation, and source files.
//
// Date Who Comments
// ==============================================================================================================
// 12/08/2004 EFW Created the code
// 04/08/2007 EFW Updated for use with .NET 2.0
//===============================================================================================================
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace EWSoftware.PDI.Windows.Forms
{
/// <summary>
/// This is used to move forward and backward through a collection of objects. It can also add, edit, and
/// delete objects from the collection.
/// </summary>
/// <remarks>Derived classes should override the virtual methods to add the required functionality</remarks>
public partial class BrowseControl : System.Windows.Forms.UserControl
{
#region Properties
//=====================================================================
/// <summary>
/// This property is used to get a reference to the binding source
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public BindingSource BindingSource => bindingSource;
/// <summary>
/// This property is used to get a reference to the error provider control
/// </summary>
[Category("Misc"), Bindable(false), Description("Error provider settings")]
public ErrorProvider ErrorProvider => epErrors;
#endregion
#region Constructor
//=====================================================================
/// <summary>
/// Constructor
/// </summary>
public BrowseControl()
{
InitializeComponent();
}
#endregion
#region Helper methods
//=====================================================================
/// <summary>
/// This should be overridden in derived classes to bind the controls to the data source
/// </summary>
/// <remarks>The default implementation does nothing</remarks>
public virtual void BindToControls()
{
}
/// <summary>
/// This should be overridden in derived classes to enable or disable the controls based on whether or
/// not there are items in the collection.
/// </summary>
/// <param name="enable">True to enable the controls, false to disable the controls</param>
/// <remarks>The default implementation does nothing. For simplicity, it is easiest to place the
/// controls in a panel and then enable or disable the panel control.</remarks>
public virtual void EnableControls(bool enable)
{
}
#endregion
#region Event handlers
//=====================================================================
/// <summary>
/// This is overridden to call the bind method for the derived class
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The event arguments</param>
private void BrowseControl_Load(object sender, EventArgs e)
{
if(!this.DesignMode)
this.BindToControls();
}
/// <summary>
/// Enable or disable the panel containing the controls based on whether or not there are items in the
/// collection.
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The event arguments</param>
private void bindingSource_ListChanged(object sender, ListChangedEventArgs e)
{
if(e.ListChangedType != ListChangedType.ItemChanged)
this.EnableControls(bindingSource.Count != 0);
}
#endregion
}
}