Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
QuestionRe: c# code to copy paste whole pivot table in another sheet of excel Pin
Eddy Vluggen20-Mar-14 10:27
professionalEddy Vluggen20-Mar-14 10:27 
Question[solved] Passage of events between WinForms Pin
Mario 5619-Mar-14 23:27
Mario 5619-Mar-14 23:27 
QuestionRe: Passage of events between WinForms Pin
Eddy Vluggen20-Mar-14 6:37
professionalEddy Vluggen20-Mar-14 6:37 
AnswerRe: Passage of events between WinForms Pin
Mario 5620-Mar-14 7:33
Mario 5620-Mar-14 7:33 
GeneralRe: Passage of events between WinForms Pin
Eddy Vluggen20-Mar-14 10:35
professionalEddy Vluggen20-Mar-14 10:35 
GeneralRe: Passage of events between WinForms Pin
Mario 5620-Mar-14 14:44
Mario 5620-Mar-14 14:44 
GeneralRe: Passage of events between WinForms Pin
Eddy Vluggen21-Mar-14 7:29
professionalEddy Vluggen21-Mar-14 7:29 
AnswerRe: Passage of events between WinForms Pin
BobJanova20-Mar-14 8:06
BobJanova20-Mar-14 8:06 
This sounds like a case when you really want a MVVM type separation of concerns. The model is whether the 6 items are 'on'; that can be affected by several things, not just the UI, so putting logic about them in the UI is wrong.

You don't actually need a VM if the model is simple enough to bind to the view, so I think what you need from a code perspective is: a model class which implements INotifyPropertyChanged so you can bind it:
class Input { // pick a more domain relevant name
 private bool on;
 public bool On {
  get { return on; }
  set { on = value; Notify("On"); }
 }

 // INPC implementation
 public event PropertyChangedEventHandler PropertyChanged;

 private void Notify(string property) {
  var handler = PropertyChanged;
  if(null != handler) handler(this, new PropertyChangedEventArgs(property));
 }
}

class DataModel {
 public IList<Input> Inputs { get; private set; }
 public DataModel() {
  Inputs = new List<Input>();
  for(int i = 0; i < 6; i++) Inputs.Add(new Input());
 }
} 


Your UI should be given the data model and data bind to it; let's imagine check boxes for the sake of simplicity, but you can use anything that has a boolean property you can bind to, including custom controls:

class MainForm : Form {
 // ...
 public MainForm(DataModel dataModel) {
  InitializeComponent();

  for(int i = 0; i < 6; i++) {
   (CheckBox)(checkBoxGroup.Controls[i]).DataBindings.Add("Checked", dataModel.Inputs[i], "On");
  }
 }
}


If you have to poll the serial port to find out the real state of these things, then that's unfortunate but it's okay. Just set the On property of the Inputs in the data model (make sure it's the same instance!) and the UI should update.

Don't bind actions to the buttons being clicked. Instead, subscribe to the property notification changes from the inputs. (Or, probably better, have the data model do that and fire a custom event instead.)
GeneralRe: Passage of events between WinForms Pin
Mario 5620-Mar-14 9:51
Mario 5620-Mar-14 9:51 
GeneralRe: Passage of events between WinForms Pin
BobJanova21-Mar-14 0:20
BobJanova21-Mar-14 0:20 
GeneralRe: Passage of events between WinForms [Solved] Pin
Mario 5621-Mar-14 6:56
Mario 5621-Mar-14 6:56 
QuestionConvert HTML content to Rtf format or save it into Rtf file without the help of interop dll in c# Pin
Member 1068161419-Mar-14 19:09
Member 1068161419-Mar-14 19:09 
AnswerRe: Convert HTML content to Rtf format or save it into Rtf file without the help of interop dll in c# Pin
Eddy Vluggen20-Mar-14 6:34
professionalEddy Vluggen20-Mar-14 6:34 
Questionc# Transform a pictureBox Pin
Ron Wensley19-Mar-14 14:06
professionalRon Wensley19-Mar-14 14:06 
AnswerRe: c# Transform a pictureBox Pin
Dave Kreskowiak19-Mar-14 14:30
mveDave Kreskowiak19-Mar-14 14:30 
GeneralRe: c# Transform a pictureBox Pin
Ron Wensley19-Mar-14 15:03
professionalRon Wensley19-Mar-14 15:03 
GeneralRe: c# Transform a pictureBox Pin
Dave Kreskowiak19-Mar-14 17:10
mveDave Kreskowiak19-Mar-14 17:10 
QuestionProblem with process.startinfo Pin
turbosupramk319-Mar-14 7:09
turbosupramk319-Mar-14 7:09 
AnswerRe: Problem with process.startinfo Pin
Richard Deeming19-Mar-14 7:28
mveRichard Deeming19-Mar-14 7:28 
GeneralRe: Problem with process.startinfo Pin
turbosupramk319-Mar-14 7:33
turbosupramk319-Mar-14 7:33 
SuggestionRe: Problem with process.startinfo Pin
Richard MacCutchan19-Mar-14 7:30
mveRichard MacCutchan19-Mar-14 7:30 
GeneralRe: Problem with process.startinfo Pin
turbosupramk319-Mar-14 7:35
turbosupramk319-Mar-14 7:35 
GeneralRe: Problem with process.startinfo Pin
Richard MacCutchan19-Mar-14 8:20
mveRichard MacCutchan19-Mar-14 8:20 
AnswerRe: Problem with process.startinfo Pin
Eddy Vluggen19-Mar-14 8:09
professionalEddy Vluggen19-Mar-14 8:09 
GeneralRe: Problem with process.startinfo Pin
turbosupramk319-Mar-14 8:26
turbosupramk319-Mar-14 8:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.