|
An array is indexed by integers regardless of its contained type, so it would be int.MaxValue .
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
|
But *right now*, int is the same as Int32 , so int.MaxValue will return the same as Int32.MaxValue . When/if they change the default integer size in the compiler to 64-bit, int.MaxValue will be the same as Int64.MaxValue .
I was doing this stuff when int was a 16-bit int, and a long was 32-bit. As a matter of fact, I was doing this stuff when an int was 8-bit, and a long was 16-bit.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
|
The index of any array is Int32, regardless of what type is stored in the array.
|
|
|
|
|
Maybe he'll understand it better if someone else tells him the same thing I did. LOL!
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Yea, sorry about that. I did not notice you actually said "the index of" in your statement. My bad.
|
|
|
|
|
So, if I understand you correctly the max number of indexes allowed in any array is int.maxvalue?
And not how ever many the cpu can hold up to infinity?
|
|
|
|
|
You're trying to use 64 bits to represent one value; I use 64 bits to represent 128 values.
0) Allocate one bit (not an integer, not even a bool) for each number you need to consider.
1) Two is the only even prime number; you only need to consider odd numbers.
In my sieve, I allocate an array of UInt64s and use a formula to determine which bit of which element represents a particular value:
The first bit of a [ 0 ] represents 1
The second bit of a [ 0 ] represents 3
The last bit of a [ 0 ] represents 127
The first bit of a [ 1 ] represents 129
etc.
|
|
|
|
|
I have a treeview and a listbox. For each node, there are some related items in the listbox. I want when the selected node in treeview changes, the items selected in the listbox change too based on the selected treeview node. How can I do that? Briefly, I want that the collection of the selected items in the listbox change in runtime.
I used a code like this:
foreach (DataRowView i in listBox_WorkOverOperationWhichinHole.Items)
{
}
but I do not know what to do next is it a true way to do that!
Thanks a lot in advance!
|
|
|
|
|
You could create a method like PopulateListItems(TreeNode currentNode) and call that method when the treeview selected node changes. The method gets all the child nodes in this example(at least should). You can make it do whatever you want.
something like this for examle:
private void PopulateList(TreeNode tn){
if (tn.Nodes.Count > 0)
{
listView1.BeginUpdate();
listView1.Items.Clear();
foreach(var tr in tn.Nodes)
{
listView1.Items.Add(tr.Text);
}
listView1.EndUpdate();
}
}
And call the method each time the select node changes.
|
|
|
|
|
Mos Dan - Lucian wrote: listView1.Items.Clear();
"I want when the selected node in treeview changes, the items selected in the listbox change too"
there is no listview, it is a ListBox, and it should not be cleared at all.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
My bad. Not reading cafrefully. But he got the ideea.
|
|
|
|
|
I would change the listbox to a datagridview. The list box need to be manually loaded rather than data bound.
I would get all the items for display in the DGV into one table and include the key from the tree node. Then you can use a dataview or a bindingsource as the datasource for the DGV and apply a filter to the dataview/bindingsource. The filter would be applied on the treeview selectednodechange event.
Something like this
dataView.RowFilter = string.Format("KeyField = '{0}', TreeNode.Tag);
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thank You Both For the Answers!
|
|
|
|
|
How can I have property that have something like this property:
item : (Collection)...
|
|
|
|
|
in toolstrip control we have a property name Item ,so i wanna have something like this.
|
|
|
|
|
I need a function to return the maximum font size (for a given font)such that a given
string will fit in a predefined box (rectangle).
That is, I want to use DrawString(string, font, brush, rectangle) to draw the string
in a fixed size box. Note that Drawstring will wrap the string automatically to fit
the width. I don't want any of the string to extend beyond the bottom of the box.
BTW, this for a windows application using forms.
Thanks for any suggestions!
Tom
modified on Saturday, January 30, 2010 5:50 PM
|
|
|
|
|
Hi,
there is Graphics.MeasureString() which calculates the required width (for single-line) or required height (for multi-line and given a fixed width); it works pretty well provided you give it the exact same parameters (font, style, etc) you are going to give DrawString later. So you would need a little iteration:
1. choose some rather large fontsize;
2. calculate required height;
3. reduce fontsize by available_size/required_size;
4. repeat 2+3 two or three times.
Warning: there are some minor deviations; I once saw a CP article on the very subject. The solution then is to use TextRenderer class; I never felt a need to do that though.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Hi Luc
I came across this myself a little while ago when I discovered some inaccuracies in MeasureString when I used it in a custom control.
In my particular situation it was more of an annoyance than a requirement so I decided to live with it, but if accurate measurement is required then MeasureString doesn't quite cut it.
Apparently MeasureCharacterRanges can help too (according to the notes I made at the time).
|
|
|
|
|
Thanks Dave, so there are three ways now. I still wonder why they can't do it right the first time and leave it there, it's not that MeasureString and DrawString are doing very different things...
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
I agree. It's something to do with aliasing in GDI IIRC but it seems a pretty poor excuse. It should be able to calculate it's own size if DrawString were to be called.
|
|
|
|
|
That solved the problem.
Thanks!
Tom
|
|
|
|
|
I did something similar a few years ago. I found the MeasureString wasn't accurate at times and the constant measuring I was forced to do came with a steep performance penalty. I solved the problem by creating a background bitmap image, big enough to fit my text in the format I required, and at 96 point size and them drew the image to a custom control to display the text, scaled down or up to the desired size. I only needed to calculate the text size once per string needed, instead of every time I had to rescale the display.
|
|
|
|
|
0) Get the pixel width of the container box.
1) Divide the box width by the number of characters in your string. This will give you your "desired average character width.
2) Get the average character width of the font that you want to use, and starting at the current font size, get the average character width. Depending on whether the average character width is less than or greater than the desired character width, loop up or down in font size until you find one that matches, or is a little smaller.
3) Once you get to a candidate font size, measure the width of your string using that font, and see if it fits. If it doesn't bump the font size up or down as appropriate.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|