Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Here is the issue:

I created my own listbox that requres an initialization variable be sent to it. The designer does not automatically put that in, so I have to edit the initialization in InitializeComponent for this listbox. I pass a vaiable to it when it is created:

MyListBox lb=new MyListBox(4);

 

The problem is that when I go back to the designer it restores the initialization to the way it was- thus, really messing thing up and making me angry.

 

Is the any way to tell the designer to put certain code in the initialization of a variable?

Or maybe a way to tell the designer not to modify that variable?

Or another idea?

C#
  • *Experts*
Posted

AFAIK, the designer won't preserve control arrays and probably never will. For control arrays, you'll have to manually create them in code. I've done similar things and put all the code in a function that I call immediately after InitializeComponent. You won't see the controls in the designer though.

 

-Ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

I'm not using control arrays. Maybe you glanced at the () and thought that was VB syntax not C#.

 

Here is a better example:

MyListBox lb=new MyListBox("Sending this string to new instance");

 

This is the way the designer seems to want it:

MyListBox lb=new MyListBox();

 

But I need a way to send something to the new instance of the control.

 

If I just need to rough it out without the designer, than so be it.

C#
Posted

Finally, some one had the same problem i did. But I could not solve it till now.

 

I made my own derived datagrid class and my constructor takes booleans to wether show the vertical and horizental scroll bars

Ex: Dim dgRules as new MyDataGrid(True,False)

but when ever i use them in the designer the designer changes them to :

Dim dgRules as new MyDataGrid()

 

I could not solve this one, but what i did is create my own initialize component and copied everything from the windows designer and pasted in in my sub and replaced the InitializeComponent by the sub i created, but I dont recommend it to anyone, you would lose the designer and anything you do in the design view you have to manually change the code in your custom function (which is extreme torture if your project is in its beginnings)

 

Hope this helps,

Dream as if you'll live forever, live as if you'll die today
  • *Gurus*
Posted
You have to create a new TypeConverter class for your listbox, and derive it from whatever typeconverter it uses as the moment. Then you have to provide a new way of converting to an InstanceDescriptor. This is the same way as in a few of the articles I've published. You then have to tell it to use your new constructor, and the designers will know how to serialize it properly.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...