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

C#

 
GeneralRe: change interface type to other interface type Pin
Keith Barrow11-Apr-14 0:38
professionalKeith Barrow11-Apr-14 0:38 
QuestionSerialize subclass of windows.forms.label Pin
DanielSheets10-Apr-14 3:08
DanielSheets10-Apr-14 3:08 
AnswerRe: Serialize subclass of windows.forms.label Pin
Ravi Bhavnani10-Apr-14 3:54
professionalRavi Bhavnani10-Apr-14 3:54 
QuestionDownload From Autoconfig Help Pin
LawlessBaron10-Apr-14 1:03
LawlessBaron10-Apr-14 1:03 
QuestionRe: Download From Autoconfig Help Pin
Eddy Vluggen10-Apr-14 3:02
professionalEddy Vluggen10-Apr-14 3:02 
AnswerRe: Download From Autoconfig Help Pin
LawlessBaron10-Apr-14 16:49
LawlessBaron10-Apr-14 16:49 
GeneralRe: Download From Autoconfig Help Pin
Eddy Vluggen11-Apr-14 7:40
professionalEddy Vluggen11-Apr-14 7:40 
Questionstrange behaviour of click method Pin
joost.versteegen10-Apr-14 0:28
joost.versteegen10-Apr-14 0:28 
hello,
I have a click method for a button and try to iterate through all comboboxes on the form. When I try to access the control through the Controls collection the program jumps out of the method (in the line Control cc = this.Controls[i];). My code is below. Can anyone tell me what I'm doing wrong here?

C#
public partial class NewTopicCtxCfgElemFrm : Form
  {
    private bool _freeConfig = false;

    public NewTopicCtxCfgElemFrm()
    {
      InitializeComponent();
    }

    public void Initialize(Topic topic)
    {
      _freeConfig = business.TopicFactory.GetTopicTypeIsFreeConfigurable(topic.ID);
      label1.Text = (_freeConfig) ? "Please select at least one of all." : "Please select all.";
      List<TopicTypeObjType> list = business.TopicFactory.GetObjTypeForTopic(topic.ID);
      int k = 0;
      foreach (var item in list)
      {
        int y = GetNewLocationTop(k);

        // add a label and a combobox to the form 
        Label lbl = new Label();
        lbl.Text = item.ObjTypeName;
        lbl.Location = new Point(10, y);
        lbl.Width = 200;
        this.Controls.Add(lbl);

        ComboBox cbx = new ComboBox();
        cbx.Location = new Point(220, y);
        cbx.Width = 200;
        cbx.Tag = item;
        this.Controls.Add(cbx);

        // set the datasource
        List<Xerox.CDMG.XControls.XDataItem> objects = business.ObjLinkFactory.GetObjForObjType(item.ObjTypeID);
        cbx.DataSource = objects;
        cbx.SelectedIndex = -1;

        // increment indexer
        k++;
      }
      // add an save-button to the form
      Button btn = new Button();
      btn.Text = "Save";
      btn.Location = new Point(10, GetNewLocationTop(k));
      btn.Width = 200;
      this.Controls.Add(btn);
      btn.Click += new EventHandler(btn_Click);
    }

    void btn_Click(object sender, EventArgs e)
    {
      try
      {
        bool checkRequiredObjTypesOk = !_freeConfig;
        // check if all required obj types are selected
        for (int i = 0; i < this.Controls.Count; i++)
        {
          Control cc = this.Controls[i];
          ComboBox cb = cc as ComboBox;
          if (cb != null)
          {
            if (!_freeConfig)
            {
              if (cb.SelectedIndex == -1) { checkRequiredObjTypesOk = false; }
            }
            else
            {
              if (cb.SelectedIndex > -1) { checkRequiredObjTypesOk = true; }
            }
          }
        }
      }
      catch (Exception exc)
      {
        Logger.LogException(exc);
      }
    }

    private int GetNewLocationTop(int k)
    {
      return k * 25 + label1.Top + label1.Height + 30;
    }

  }

AnswerRe: strange behaviour of click method Pin
Rob Philpott10-Apr-14 0:50
Rob Philpott10-Apr-14 0:50 
GeneralRe: strange behaviour of click method Pin
joost.versteegen10-Apr-14 1:13
joost.versteegen10-Apr-14 1:13 
GeneralRe: strange behaviour of click method Pin
Rob Philpott10-Apr-14 1:44
Rob Philpott10-Apr-14 1:44 
GeneralRe: strange behaviour of click method Pin
joost.versteegen10-Apr-14 1:47
joost.versteegen10-Apr-14 1:47 
GeneralRe: strange behaviour of click method Pin
Rob Philpott10-Apr-14 1:53
Rob Philpott10-Apr-14 1:53 
GeneralRe: strange behaviour of click method Pin
joost.versteegen10-Apr-14 3:38
joost.versteegen10-Apr-14 3:38 
GeneralRe: strange behaviour of click method Pin
Dave Kreskowiak10-Apr-14 3:55
mveDave Kreskowiak10-Apr-14 3:55 
AnswerRe: strange behaviour of click method Pin
Richard MacCutchan10-Apr-14 2:31
mveRichard MacCutchan10-Apr-14 2:31 
GeneralRe: strange behaviour of click method Pin
joost.versteegen10-Apr-14 3:27
joost.versteegen10-Apr-14 3:27 
GeneralRe: strange behaviour of click method Pin
Richard MacCutchan10-Apr-14 3:39
mveRichard MacCutchan10-Apr-14 3:39 
AnswerRe: strange behaviour of click method Pin
Eddy Vluggen10-Apr-14 3:01
professionalEddy Vluggen10-Apr-14 3:01 
GeneralRe: strange behaviour of click method Pin
joost.versteegen10-Apr-14 3:30
joost.versteegen10-Apr-14 3:30 
GeneralRe: strange behaviour of click method Pin
Eddy Vluggen10-Apr-14 4:59
professionalEddy Vluggen10-Apr-14 4:59 
GeneralRe: strange behaviour of click method Pin
joost.versteegen10-Apr-14 7:52
joost.versteegen10-Apr-14 7:52 
QuestionRe: strange behaviour of click method Pin
Eddy Vluggen10-Apr-14 11:03
professionalEddy Vluggen10-Apr-14 11:03 
AnswerRe: strange behaviour of click method Pin
Bernhard Hiller10-Apr-14 23:07
Bernhard Hiller10-Apr-14 23:07 
QuestionI need code for sending SMS through asp.net in c# Pin
Member 107033699-Apr-14 23:30
Member 107033699-Apr-14 23:30 

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.