|
Why when I place DefaultValueAtribute before property to set a specific value, the result with that value is not seen in the property panel.
e.g
[DefaultValueAttribute(23)]
public int MyProperty
{
get { return myVar; }
set { myVar = value; }
}
In that case i see "0" value in property panel.
What is wrong?
|
|
|
|
|
The DefaultValueAttribute specifies the value your property is set to when you select "Reset" in a PropertyGrid.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Doesn't the property window of VS Designer contains PropertyGrid?
How to do that the defalt value of a property was displayed in Property Window and its code was automaticaly generated?
|
|
|
|
|
You simply have to write
myVar = 23; in the constructor of your class so that the property has its default value initially.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Thanks, i know that this code will work out. But the case is that I'm writing a component and it has properties. Some of them have default values that can be changed at design time. It should work like in other standard components which place their default value in a special area at design time when they droped on th design area and/or their properties changed.
That is what i need.
The constructor is good, but the values will be strictly embedded in component in that way what i exactly don't want
Regards,
Aleksey
|
|
|
|
|
alexeychik2001 wrote: Some of them have default values that can be changed at design time.
To what control do you refer here?
alexeychik2001 wrote: The constructor is good, but the values will be strictly embedded in component in that way what i exactly don't want
You want a variable default value? That's not how it works...
The default value is used to decide whether to serialize the property and whether to show the property value in the grid itself as bold or not.
I don't think you can have instance default values (supported by VS and the property grid, anyway).
Share and enjoy.
Sean
|
|
|
|
|
Take any control, for instance Timer and its property Interval. If you take a look on its metadata you'll see
[DefaultValue(100)]
public int Interval { get; set; }
I don't want a varable defaul value. I want that this default value could be seen at design time and changed at property window. How to do it?
|
|
|
|
|
alexeychik2001 wrote: Take any control, for instance Timer and its property Interval. If you take a look on its metadata you'll see
[DefaultValue(100)]
public int Interval { get; set; }
I don't want a varable defaul value. I want that this default value could be seen at design time and changed at property window. How to do it?
You can't. The default value is, as you see, compiled in the code. There is only 1 default value that a Timer.Interval property can have, and it's set at compile time.
You can't change that at design time, and you can't change it at run-time.
You can create a new control inherited from Timer that has a different default value for Interval (I just tried it), but all instances of that control will only have the single default value.
namespace WindowsApplication1{
class MyTimer : System.Windows.Forms.Timer {
public MyTimer() {
base.Interval = 200;
}
[System.ComponentModel.DefaultValue(200)]
public new int Interval {
get { return base.Interval; }
set { base.Interval = value; }
}
}
}
All instances of this new control have a default value of 200 for Interval , but it requires the code in the constructor, and it's constant for all uses (design time or run-time).
Share and enjoy.
Sean
|
|
|
|
|
here are my listview codes.i wanna add file sizes next to the folder names.what should i have to add between this codes or somewhere else? any idea?
private void txtDirectory_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if( e.KeyData == Keys.Enter )
{
if( System.IO.Directory.Exists( txtDirectory.Text ) == false )
{
MessageBox.Show( "Directory Does Not Exist", "Invalid Directory", MessageBoxButtons.OK, MessageBoxIcon.Information );
return;
}
tree.Load( txtDirectory.Text );
}
|
|
|
|
|
Take a look at the SubItems collection of the ListViewItem class.
|
|
|
|
|
Hi all,
I have some problem with binded ComboBox:
I have class GsmNumber:
class GsmNumber
{
private int? _CompanyID;
public int? CompanyID
{
get { return _CompanyID; }
set { _CompanyID = value; }
}
}
And Company class:
class Company
{
private int _CompanyID;
public int CompanyID
{
get { return _CompanyID; }
set { _CompanyID = value; }
}
private string _CompanyName;
public string CompanyName
{
get { return _CompanyName; }
set { _CompanyName = value; }
}
public static List<Company> GetCompanyList()
{
return new List<Company>();
}
}
And I have form with ComboBox ( _uiCompany ):
_uiCompany.DisplayMember = "CompanyName";
_uiCompany.ValueMember = "CompanyID";
_uiCompany.DataSource = Firma.GetCompanyList();
GsmNumber oNumber = new GsmNumber();
oNumber.CompanyID = 3;
_uiCompany.DataBindings.Add("SelectedValue", oNumber, "CompanyID");
So I have ComboBox with ArrayList datasource and binded SelectedValue property. It works good (in combobox selected item is Company object with CompanyID = 3), but when i change item in combobox oNumber.CompanyID not changing! Why?
P.S. Sorry for ma English
|
|
|
|
|
|
hi,
does anyone know how can I make
form not inside my app transparent?
|
|
|
|
|
That's not a good idea. You could crash the application if it's doing something to the window that isn't supported by Layered Windows.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
1 Text box, 1 Context menu.
Well, i didn't want the context menu, so i got rid of it, like this:
this.textBox.ContextMenu = new ContextMenu();
And now it is gone, and it works. But, and you can try this yourself, if you right click it, and then drag away from the text box, when you release the mouse button, the menu appears, and you can copy / paste / undo etc.
Crazy huh?
|
|
|
|
|
Good Morning,
i have a problem again!
i have a form with a DataGrid.
imagine a datagrid with three rows, ok!
the focus is on first row and i click on enter it goes to second when i click again until the third row. when it is last row the focus stay there. i'd like it return to first row when i click on enter again.
Thanks a lot!
|
|
|
|
|
how do i insert an icon in the taskbar at runtime?
|
|
|
|
|
I guess you're looking for the NotifyIcon .
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
i want to update a record that binds to the table,how do i this work?
|
|
|
|
|
I am trying to make a picturebox transparent (except the border). I selected the background to be (web-transparent), but that didn't work.
Is there a better object to use? I want to be able to move around the borders of a rectangle and show the picture under it.
|
|
|
|
|
Is there a way just to draw an empty rectangle?
|
|
|
|
|
Years ago (1998) I wrote an MTS application that had a C++/ATL middleware and a VB 6.0 front-end. I remember an object (Collection) that you could stuff unique values into. It would throw an error if your values were not unique. You could trap the error and continue adding values. What made it nice is you didn't have to manually iterate the data structure checking for uniqueness before inserting your values. Does C# have such a data structure? I can write one but if there's an intrinsic structure that takes a key, value pair that would be great.
Anybody know of such a beast?
My name is Maximus Decimus Meridius, Commander of the Armies of the North, General of the Felix Legions, loyal servant to the true emperor, Marcus Aurelius. Father to a murdered process, husband to a murdered thread. And I will have my vengeance, in this life or the next. - Gladiator
I work to live. I do not live to work. My clients do not seem capable of grasping this fact.
|
|
|
|
|
You can always check Contains(newObject) before inserting the object into a List. Then you insert the value if it does not already exist.
|
|
|
|
|
Seems like the last time I tried that I got bogus results... I'll try it again...
My name is Maximus Decimus Meridius, Commander of the Armies of the North, General of the Felix Legions, loyal servant to the true emperor, Marcus Aurelius. Father to a murdered process, husband to a murdered thread. And I will have my vengeance, in this life or the next. - Gladiator
I work to live. I do not live to work. My clients do not seem capable of grasping this fact.
|
|
|
|
|
Hi!
Doesn't any collection implementing IDictionary give you what you want?
If you try to add an element whose key already exists in the dictionary, an ArgumentException is thrown...
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|