Skip to content

Instantly share code, notes, and snippets.

@hartbit
Last active December 19, 2015 12:48
Show Gist options
  • Save hartbit/5957104 to your computer and use it in GitHub Desktop.
Save hartbit/5957104 to your computer and use it in GitHub Desktop.
public class GenerationEntry : INotifyPropertyChanged
{
private int quantity;
private int size;
private Level level;
public event PropertyChangedEventHandler PropertyChanged;
public GenerationEntry()
{
this.Quantity = 1;
this.Size = 8;
this.Level = Level.One;
}
public int Quantity
{
get
{
return this.quantity;
}
set
{
if (value != this.quantity)
{
Debug.Assert(value > 0);
this.quantity = value;
NotifyPropertyChanged();
}
}
}
public int Size
{
get
{
return this.size;
}
set
{
if (value != this.size)
{
Debug.Assert((value >= 4) && (value % 2 == 0));
this.size = value;
NotifyPropertyChanged();
}
}
}
public Level Level
{
get
{
return this.level;
}
set
{
if (value != this.level)
{
this.level = value;
NotifyPropertyChanged();
}
}
}
public override string ToString()
{
return String.Format("{0} puzzles {1}x{1} de niveau {2}", this.quantity, this.size, (int)this.level);
}
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
System.ArgumentException: Cannot bind to the property or column Quantity on the DataSource.
Parameter name: dataMember
at System.Windows.Forms.BindToObject.CheckBinding()
at System.Windows.Forms.BindToObject.SetBindingManagerBase(BindingManagerBase lManager)
at System.Windows.Forms.Binding.SetListManager(BindingManagerBase bindingManagerBase)
at System.Windows.Forms.ListManagerBindingsCollection.AddCore(Binding dataBinding)
at System.Windows.Forms.BindingsCollection.Add(Binding binding)
at System.Windows.Forms.BindingContext.UpdateBinding(BindingContext newBindingContext, Binding binding)
at System.Windows.Forms.Control.UpdateBindings()
at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.ScrollableControl.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.OnParentVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.ScrollableControl.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Form.OnVisibleChanged(EventArgs e)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Takuzu.Generator.Program.Main() in c:\Users\David\Documents\GitHub\Takuzu\Takuzu.Generator\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
public partial class MainForm : Form
{
private BindingList<GenerationEntry> generationList = new BindingList<GenerationEntry>();
public MainForm()
{
InitializeComponent();
this.listBoxGeneration.DataSource = this.generationList;
this.numericUpDownGenerationCount.DataBindings.Add(
"Value",
this.listBoxGeneration,
"SelectedValue.Quantity",
false,
DataSourceUpdateMode.OnPropertyChanged);
}
private void buttonGenerationAdd_Click(object sender, EventArgs e)
{
this.generationList.Add(new GenerationEntry());
}
private void buttonGenerationRemove_Click(object sender, EventArgs e)
{
this.generationList.RemoveAt(this.listBoxGeneration.SelectedIndex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment