Author Topic: Control Arrays  (Read 3599 times)

0 Members and 1 Guest are viewing this topic.

Draftek

  • Water Moccasin
  • Posts: 1501
Control Arrays
« on: January 31, 2006, 11:28:37 AM »
I'm building a C# application using the Model-View-Controller technique.

I've built a form (with no code) that looks like Windows explorer with a menu, tool menu, address combo box, and treeview / listview splitter.

Anyway, in the controller app which contains the code to add and trap events of the items in the form. The menu has some items which are checked menu items that should act like a radio button optioin list. For instance, I'm going to allow the user to view drawing previews in the listview control at a large size, small size or details just like explorer does. When the user selects one of these options the others should be unchecked. In addtition, the toolbar strip that contains a dropdownbutton control should also by synced accordingly.

In order to not have a gazillion event handlers, I'm using a single event handler for the menu items and select case on the tag (set by me in code) to determine which menu item was selcted. The problem is, there is a fair amount of code to sync the checked items.
Here is an example of a two-toggle menu item for local details / web details to sync the menu buttons and the toolbar button:
Code: [Select]
case "File1":
// menu File Locals details was selected

// toggle this along with File2 menu item
if (mnuItem.Checked)
{
mnuFileWeb.Checked = false;
mnuFileLocal.Checked = true;
// sync the tool strip button too
toolConnect.Text = "Local Details";
toolConnect.Image = Properties.Resources.File1.ToBitmap();
}
else
{
mnuFileWeb.Checked = true;
mnuFileLocal.Checked = false;
toolConnect.Text = "Web Details";
toolConnect.Image = Properties.Resources.File2.ToBitmap();
}
break;
case "File2":
// menu file Web details was selected

if (mnuItem.Checked)
{
mnuFileLocal.Checked = false;
mnuFileWeb.Checked = true;
toolConnect.Text = "Web Details";
toolConnect.Image = Properties.Resources.File2.ToBitmap();
}
else
{
mnuFileLocal.Checked = true;
mnuFileWeb.Checked = false;
toolConnect.Text = "Local Details";
toolConnect.Image = Properties.Resources.File1.ToBitmap();
}
break;

You can imagine this could get complex with more than a couple of options.

How are you guys simulating control arrays for .Net development?

« Last Edit: January 31, 2006, 11:34:42 AM by Draftek »
Soli Deo Gloria

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Control Arrays
« Reply #1 on: January 31, 2006, 04:23:20 PM »
Haven't played with Control Arrays or done much Menu work, but I cant Imagine how to reduce the code required to make them work ... after all, there can be a lot of decision logic involved with menu's.
kdub in one timeline.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<-

MickD

  • King Gator
  • Posts: 3520
  • (x-in)->[process]->(y-out)
Re: Control Arrays
« Reply #2 on: January 31, 2006, 04:45:37 PM »
Can you handle the checking/setting using the control array itself?
ie. if you pick 'large' setting, use a function passing in the index of the 'large' control to check that item then uncheck the other items in the control array in a loop.
rough outline eg.

uncheckItems(int controlIndex)
{
    for(int i = 0; i < array.size(); i++)
        if( i == array)
            checkitem
        else
            uncheckitem
}
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

"The E in Javascript stands for 'easy'." Florin Pop tweet

Draftek

  • Water Moccasin
  • Posts: 1501
Re: Control Arrays
« Reply #3 on: January 31, 2006, 05:31:53 PM »
hmm. That might work if I use the tag to store the index and query the text for the event handler.

Thanks. I'll ponder that some.
Soli Deo Gloria

MickD

  • King Gator
  • Posts: 3520
  • (x-in)->[process]->(y-out)
Re: Control Arrays
« Reply #4 on: January 31, 2006, 05:42:16 PM »
updated rough outline to include the array -

uncheckItems(int controlIndex, Array controlarray)
{
    for(int i = 0; i < controlarray.size(); i++)
        if( i == array)
            checkitem
        else
            uncheckitem
}
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

"The E in Javascript stands for 'easy'." Florin Pop tweet