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

C#

 
AnswerRe: Accessing dBase files with C# Pin
Heath Stewart5-Oct-05 9:15
protectorHeath Stewart5-Oct-05 9:15 
GeneralRe: Accessing dBase files with C# Pin
TheMajorRager5-Oct-05 11:37
TheMajorRager5-Oct-05 11:37 
AnswerRe: Accessing dBase files with C# Pin
Heath Stewart5-Oct-05 11:40
protectorHeath Stewart5-Oct-05 11:40 
GeneralRe: Accessing dBase files with C# Pin
TheMajorRager5-Oct-05 12:14
TheMajorRager5-Oct-05 12:14 
GeneralRe: Accessing dBase files with C# Pin
TheMajorRager5-Oct-05 13:54
TheMajorRager5-Oct-05 13:54 
Questioncheckbox ques Pin
ter815-Oct-05 7:13
susster815-Oct-05 7:13 
GeneralRe: checkbox ques Pin
Guffa5-Oct-05 8:57
Guffa5-Oct-05 8:57 
AnswerRe: checkbox ques Pin
Heath Stewart5-Oct-05 9:10
protectorHeath Stewart5-Oct-05 9:10 
You should use RadioButtons, then, within the same container control. Not only do they already provide the functionality you want, but it gives the user a consistent experience which is very important for applications. Great care goes into creating Windows and Windows applications to make sure users have a consistent experience. ISVs should follow these guidelines as well.

If you have a legitemate reason for using CheckBoxes, you'll have to clear them yourself. I recommend writing a separate class that uses a list with you can add CheckBoxes to and then have methods to clear all except the one that was checked. You could also simply enumerate all controls in your container using the Control.Controls property and - if the current enumerated control is a CheckBox and it's not the one that was clicked, clear the check mark. It also allows you to logically group differnet check boxes even if they're in the same container or different containers.

The former - using a separate class - is more flexible and scalable. A simple example follows:
using System;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;
 
class CheckBoxManager
{
  ArrayList cbs;
  bool changing = false;
 
  public CheckBoxManager()
  {
    cbs = new ArrayList();
  }
 
  public void Add(CheckBox cb)
  {
    if (cb == null) throw new ArgumentNullException("cb");
    cbs.Add(cb);
    cb.CheckedChanged += new EventHandler(OnCheckChanged);
  }
 
  public void AddRange(IEnumerable cbs)
  {
    if (cbs == null) throw new ArgumentNullException("cbs");
    foreach (object obj in cbs)
    {
      CheckBox cb = obj as CheckBox;
      if (cb != null) Add(cb);
    }
  }
 
  void OnCheckChanged(object sender, EventArgs e)
  {
    // Don't run if we're current changing the Checked property
    // for each CheckBox.
    if (changing) return;
    else changing = true;
 
    foreach (CheckBox cb in cbs)
    {
      if (sender != cb) cb.Checked = false;
    }
 
    changing = false;
  }
}
 
class Test : Form
{
  static void Main()
  {
    Application.Run(new Test());
  }
 
  Test()
  {
    CheckBoxManager group0 = new CheckBoxManager();
    CheckBoxManager group1 = new CheckBoxManager();
    int top = 8;
 
    for (int i = 0; i < 10; i++)
    {
      bool isgroup0 = i % 2 == 0;
 
      CheckBox cb = new CheckBox();
      if (isgroup0) group0.Add(cb);
      else group1.Add(cb);
      Controls.Add(cb);
 
      cb.Text = string.Format("CheckBox{0} (Group {1})", i, i % 2);
      cb.Top = top;
      cb.Left = 8;
      cb.Width = 200;
      top = cb.Bottom + 8;
    }
 
    Height = SystemInformation.CaptionHeight + top;
    Text = "CheckBoxManager Example";
  }
}


This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft

[My Articles] [My Blog]
QuestionChanging the colour &amp; font of (null) value datagrid entries Pin
Red_Wizard_Shot_The_Food5-Oct-05 6:58
Red_Wizard_Shot_The_Food5-Oct-05 6:58 
AnswerRe: Changing the colour &amp; font of (null) value datagrid entries Pin
Heath Stewart5-Oct-05 8:43
protectorHeath Stewart5-Oct-05 8:43 
QuestionAdding a chart to my form Pin
james3775-Oct-05 6:25
james3775-Oct-05 6:25 
AnswerRe: Adding a chart to my form Pin
enjoycrack5-Oct-05 14:24
enjoycrack5-Oct-05 14:24 
GeneralRe: Adding a chart to my form Pin
james3776-Oct-05 7:16
james3776-Oct-05 7:16 
GeneralRe: Adding a chart to my form Pin
enjoycrack6-Oct-05 10:43
enjoycrack6-Oct-05 10:43 
Questionpaste/insert text at cursor position in a rich text box Pin
Agyeman5-Oct-05 6:13
Agyeman5-Oct-05 6:13 
AnswerRe: paste/insert text at cursor position in a rich text box Pin
Heath Stewart5-Oct-05 8:39
protectorHeath Stewart5-Oct-05 8:39 
QuestionSocket.BeginSend and AsyncCallBack Delegate problems Pin
Lilli Alexis5-Oct-05 5:57
Lilli Alexis5-Oct-05 5:57 
Questionpaste/insert text at cursor position in a rich text box Pin
Agyeman5-Oct-05 5:34
Agyeman5-Oct-05 5:34 
AnswerRe: paste/insert text at cursor position in a rich text box Pin
mav.northwind5-Oct-05 8:24
mav.northwind5-Oct-05 8:24 
GeneralRe: paste/insert text at cursor position in a rich text box Pin
Agyeman5-Oct-05 8:34
Agyeman5-Oct-05 8:34 
QuestionHow to place line cap code for arrow?? Pin
...---...5-Oct-05 5:13
...---...5-Oct-05 5:13 
AnswerRe: How to place line cap code for arrow?? Pin
Andy Moore5-Oct-05 6:37
Andy Moore5-Oct-05 6:37 
GeneralRe: How to place line cap code for arrow?? Pin
...---...5-Oct-05 6:45
...---...5-Oct-05 6:45 
GeneralRe: How to place line cap code for arrow?? Pin
Andy Moore5-Oct-05 6:57
Andy Moore5-Oct-05 6:57 
AnswerRe: How to place line cap code for arrow?? Pin
Robert Rohde5-Oct-05 8:31
Robert Rohde5-Oct-05 8:31 

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.