|
Hi all,
I wish to add line numbers next to a Listview control.
I don't want this line numbers to be the first Listview column, but a different control next to it.
I thought of using a simple Textbox, but I can't find convenient way to synchronize between the Listview lines and the Textbox lines (Height and location).
Does anyone have an idea? Maybe a different control?
Thanks a lot,
Eyal.
|
|
|
|
|
eyalbi007 wrote: I don't want this line numbers to be the first Listview column, but a different control next to it.
This is the efficient way to do this. If you use a separate control, it will be tough to maintain the correct position when list view scrolls.
Create a new control and inherit that from ListView class. Provide option for adding serial number. This allows you to re-use the control.
|
|
|
|
|
Quick question- can I programtically set the value of a custom attribute?
--Here is an example of what I am currently doing and it works--
<br />
[IcVPNPlugin]<br />
public class myVPN : IVPN<br />
{<br />
<br />
<br />
private VPNState _state;<br />
private List<string> _profiles;<br />
private string[] _stringArr;<br />
private string _username;<br />
private string _password;<br />
private string _profile;<br />
private string _profileTest;<br />
<br />
<br />
<br />
public myVPN()<br />
{<br />
_profiles = new List<string>();<br />
GetProfiles();<br />
<br />
<br />
_stringArr = new string[this.Profiles.Count];<br />
for (int i=0; i<=this.Profiles.Count; i++)<br />
{<br />
_stringArr[i] = this.Profiles[i];<br />
}<br />
}<br />
<br />
<br />
<br />
[BrowsableAttribute(true), TypeConverter(typeof(DropdownConverter)), RequiredParameter(false, ParameterType = typeof(String)), DropdownValues(new string[] { "profile list 2-0", "profile list 2-1", "profile list 2-2" }, Name = "ProfileTest")]<br />
public string ProfileTest<br />
{<br />
get { return _profileTest; }<br />
set { _profileTest = value; }<br />
}<br />
...But I would like to programatically set the values of the DropdownValues attribute as such:
<br />
[IcVPNPlugin]<br />
public class myVPN : IVPN<br />
{<br />
<br />
<br />
private VPNState _state;<br />
private List<string> _profiles;<br />
private string[] _stringArr;<br />
private string _username;<br />
private string _password;<br />
private string _profile;<br />
private string _profileTest;<br />
<br />
<br />
<br />
public myVPN()<br />
{<br />
_profiles = new List<string>();<br />
GetProfiles();<br />
<br />
<br />
_stringArr = new string[this.Profiles.Count];<br />
for (int i=0; i<=this.Profiles.Count; i++)<br />
{<br />
_stringArr[i] = this.Profiles[i];<br />
}<br />
}<br />
<br />
<br />
<br />
[BrowsableAttribute(true), TypeConverter(typeof(DropdownConverter)), RequiredParameter(false, ParameterType = typeof(String)), DropdownValues(_stringArr, Name = "ProfileTest")]<br />
public string ProfileTest<br />
{<br />
get { return _profileTest; }<br />
set { _profileTest = value; }<br />
}<br />
Of course this doesn't work- which is why I am posing the question here. Is there any way at all to be able to accomplish this? I am pretty sure that properties are instantiated by the CLR before the contructor. So if that is true, then any work I did in the contructor that would be passed to the attribute would just be too late- which, I think, is why this isn't working. But perhaps a static property could work? Now I am just guessing... Thanks much!
|
|
|
|
|
Yes they are readonly.
You can only set attributes through reflection.emit.
So you can set attribs on classes that you build or inherit by using emit, but thats it.
|
|
|
|
|
In System.Reflection, attributes are read-only.
But System.ComponentModel (which is used by the property grid) allows for filtering and modifying attributes when they are requested, take a look at the ICustomTypeDescriptor interface.
|
|
|
|
|
I need to create code that goes through the array, and for each empty slot, allocate a Student object. You should assign the new object a Student ID number that is the same as the slot in the array (i.e., if slot #7 is blank, create a Student object with ID # 7). You should NOT destroy any existing Student objects
How should I start this assignment.
|
|
|
|
|
Well you could start by reading about arrays.
After reading through that article I would think your assignment would be a breeze.
Mark.
|
|
|
|
|
Honestly, if the material your teacher gave you doesn't give you a starting point, I'd approach some other students to work out if the problem is with you, or with the teacher. If the other students also don't know how to start, approach the teacher. If they do, then follow the advice given before, read your course materials, use google and then take a shot at it.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I know definition of volatile keyword [^] but still couldnt use it anywhere in my application. Not sure if I know where exactly to use it?
What are we trying to achieve indicating a variable as volatile?? How CLR will treat it differently??
Keep DotNetting!!
GeekFromIndia
|
|
|
|
|
geekfromindia wrote: What are we trying to achieve indicating a variable as volatile?? How CLR will treat it differently??
When you modify a variable there is often a version of it cached in the processor. Applying the volitile keyword indicates that this optimization should not be used and it must be updated in memory as multiple threads are accessing it. If you update the variable in the processor cache and another thread requests it from memory the the value will be wrong.
|
|
|
|
|
how does that differ from variable in single threaded environment?? is information regarding optimization is available to only a single thread?
Keep DotNetting!!
GeekFromIndia
|
|
|
|
|
<muse>
Sometimes I wonder what will happen to the next generation of software engineers .. I grew up poking memory locations to alter my Atari's OS and progressed to debugging accidental pointer overruns in C. What happens when there's no concept of the architecture on which our beautifully abstract code runs I wonder?
</muse>
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
thanks for your thought MidwestLimey...
could you please shed some light on this topic so just to help your next generation building some robust applications..
Keep DotNetting!!
GeekFromIndia
|
|
|
|
|
Sorry just logged in, but it looks as if your question was answered. I learned most of what I know by playing around and asking questions - still amazed at how little I learned at uni in hindsight
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
As long as the world turns there will always be geeks - computer/software engineering will only move forward. .
Mark
|
|
|
|
|
MarkBrock wrote: As long as the world turns there will always be geeks - computer/software engineering will only move forward. .
Right said Mark...
Colin Angus Mackay wrote: If you update the variable in the processor cache and another thread requests it from memory the the value will be wrong.
My Ques: (rephrasing it a bit) - If we say that a thread1 reads a variable from memory and that is stored in CPU cache for optimization. now thread1 accesses that variable from cache all the time...why doesn't other threads access that variable from cache instead of going to memory.
So it seems that here optimization is being done by thread1 so it cannot be accessed from thread2 which will always access variable again from memory causing all the problem.
here's an example on volatile for more details:
int i = 0;
loop(i=0 to i=100)
{
//do something
}
here if compiler optimizes the variable before loop, it will have value 0 in memory and loop will only update value in cache.
Now if any other method tried accessing this variable inbetween this loop it will get an outdated value.
Declaring variable i as volatile tells compiler to not to optimize it in cache.
Keep DotNetting!!
GeekFromIndia
|
|
|
|
|
geekfromindia wrote: now thread1 accesses that variable from cache all the time...why doesn't other threads access that variable from cache instead of going to memory.
Because the optimisation might not be a cache. It might be a processor register, which naturally is local to the thread.
Consider for example a piece of code like this:
i = i + 1;
i = i * 2;
i = i - 4;
The compiler may determine that this code can be optimised using a processor register into something like:
reg = i
reg.add(1)
reg.mul(2)
reg.sub(4)
i = reg
In the optimised version, the variable will be unchanged until all the calculations has been done, never seeing the intermediate values. By making the variable volatile, you tell the compiler that the variable has to be updated for each calculation.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Normally, it is valid for the compiler to do an optimization like this:
while (!abort) {
}
->
bool condition = !abort;
while (condition) {
}
Now if another thread sets "abort = true;", this won't be visible in the loop because the old abort value was "cached"; so the loop will run forever. Marking abort as volatile tells the compiler it that might be changed by other threads and must not be cached.
|
|
|
|
|
hi every one.
i want to make an application in c# through which two person can chatt from 2 different pc.
i dont know how to do voice chatting..so plz help me if some one know....
thanks
|
|
|
|
|
|
|
Hello,
I'm working in MS Visual C# 2005 Express.
I recently stumbled upon a nice "vista-like" button class posted here on codeproject.
http://www.codeproject.com/KB/miscctrl/VistaButton.aspx[^]
It's worked fine for one of my projects, except that I cannot set the DialogResult on one of those custom buttons, like you can a regular button.
I'm trying to add it manually into the vistabutton User Control but I have no luck so far. This is what I have added:
private DialogResult dResult = DialogResult.OK;<br />
<br />
public DialogResult DialogResult<br />
{<br />
get { return DialogResult.OK; }<br />
set { dResult = value; }<br />
}
And i'm trying to use it like this in my designer code:
this.button8.DialogResult = System.Windows.Forms.DialogResult.OK;
I'm still a newb coder, can someone point out my errors? It compiles and runs fine.. but doesn't return the dialogresult
|
|
|
|
|
Ok, I made a few changes but it still does not seem to work.
private DialogResult dResult = DialogResult.None;<br />
<br />
public DialogResult DialogResult<br />
{<br />
get { return dResult; }<br />
set { dResult = value; }<br />
}
|
|
|
|
|
The form's DialogResult property needs to be set to the button'd DialogResult property when clicked so in the button8 Click event enter this code
this.DialogResult = button8.DialogResult;
Dave
|
|
|
|
|
Yes! That was it. Thanks!!
|
|
|
|