|
yosif4444 wrote: int IComparable.CompareTo(object x)
{
Test x1 = (Test)x;
return (this.x.CompareTo(x1.x));
}
Your compare to can do whatever you like. You return an int, which specifies how far apart two items are, and in what direction. If you want to sort for y within x, then this would work:
if (x == x1.x)
{
return y - x1.y);
}
else
{
return x - x1.x;
}
Or, pass on to the int compareTo, if you want.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
i think i described my problem wrong
i want to sort the list with either x or y not with both of them
say
object1 x = 5, y = 10
object2 x = 3, y = 7
object3 x = 7, y = 4
Test.Sort() //for x
output
object2
object1
object3
or
Test.Sort() //for y
output
object3
object2
object1
i hope u got wat i mean
thanks
|
|
|
|
|
yosif4444 wrote: i want to sort the list with either x or y not with both of them
So what part of "do whatever you like" don't you understand?
Christian Graus wrote: Your compare to can do whatever you like
led mike
|
|
|
|
|
I know that i can "do whatever i want" but only in one compare function
i want to write many compare functions depending on the variable i want
|
|
|
|
|
OK - I get it.
Create an enum for the different sort orders, then use an instance of that to decide what to do in the compare function.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Yeah you got my point
but can u plz help me with code example, coz i don't know how to implement wat u said
thanks in advance
|
|
|
|
|
OK, it's pretty simple
public class SamplesArrayList
{
public class Test : IComparable
{
public enum SortBy { SortByX, SortByY };
private SortBy _sortOrder;
public SortBy
{
get { return _sortOrder; }
set { _sortOrder = value; }
}
public int x;
public int y;
//this is the variable which i want to sort the list with it also
public Test(int x)
{
this.x = x;
}
int IComparable.CompareTo(object x)
{
Test x1 = (Test)x;
switch(SortOrder)
{
int result;
case SortBy.SortByX:
result = (this.x.CompareTo(x1.x));
break;
case SortBy.SortByY:
result = (this.y.CompareTo(x1.y));
break;
default:
throw new ArgumentException("The SortBy enum has been added to, but the CompareTo method has not been updated");
break;
}
return result;
}
}
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Try it ---
using System;
using System.Collections;
using System.Collections.Generic;
public class SamplesArrayList
{
static char indi;
public class Test : IComparable
{
public int x;
public int y;
//this is the variable which i want to sort the list with it also
public char indi;
public Test(int x, int y)
{
this.x = x;
this.y = y;
}
int IComparable.CompareTo(object x)
{
if (indi == 'X')
{
Test x1 = (Test)x;
return (this.x.CompareTo(x1.x));
}
else
{
Test y1 = (Test)x;
return (this.y.CompareTo(y1.y));
}
}
}
public static void Main()
{
ArrayList test = new ArrayList();
Test l1 = new Test(7,8);
Test l2 = new Test(3,2);
Test l3 = new Test(9,1);
Test l4 = new Test(2,0);
Test l5 = new Test(4,5);
indi = 'X';
test.Add(l1);
test.Add(l2);
test.Add(l3);
test.Add(l4);
test.Add(l5);
test.Sort();
foreach (Test t in test)
{
Test x1 = t;
Console.WriteLine(x1.x+ " "+ x1.y);
}
Console.ReadKey();
}
}
|
|
|
|
|
using a char is obviously nasty as hell, but this is the general idea, yes.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
|
Dear FRiends,
We have Imported a DLL in c# which made in VC++.While calling the function of imported dll ,named
void Testing_Function(
ref coordpt[,] polygons, ref int[] polygons_vertex_num, ref double[] polygons_rotation_angle, ref int []polygons_flip, ref
double []polygons_rotation_tolerance, ref int []polygons_placement_group, int polygons_num, double surface_width, double
surface_pattern, double x_rapport, double y_rapport, double x_rapport_offset, double y_rapport_offset, int layer_type, int
layer_type_length_option, ref coordpt[,] holes, ref int[] holes_vertex_num, int holes_num, int product_type, int
number_of_product_pieces, int marker_combi_type, double allowed_time, double termination_yield, ref int manual_interrupt,
ref int intermediate_solution, ref int error_message,ref Nesting_Constraint_Type[]constraints, int constraints_number, ref
int[] polygon_placed, ref double[] x_translation, ref double[] y_translation, ref double[] rotation, ref int[] flip, ref
double[] marker_length1, ref double[] marker_length2, ref double[] marker_yield, int dump
);
in c#.
it is giving Exception as
AccessViolationException was Handled
---------------------------------------
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
plz help me out for this problem asap.
|
|
|
|
|
That's one awful function. Have you considered creating a struct or two, to limit the parameter list ?
The C++ dll has some sort of memory management problem, but how can we know what it is, without seeing the code ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
DLL Function in VC++
This is actullay contained 38 parameters.
void Testing_Function
(
coordpt **polygons, /*polygon shapes*/
int *polygons_vertex_num, /*polygon vertex numbers*/
double *polygons_rotation_angle , /*polygon rotation angles*/
int *polygons_flip, /*polygon flip information*/
double *polygons_rotation_tolerance, /*polygon rotation tolerances*/
int *polygons_placement_group, /*polygon placement groups
int polygons_num, /*number of polygons*/
double surface_width, /*width of the surface*/
double surface_pattern, /*pattern on the surface*/
double x_rapport, /*pattern repeat in x-direction*/
double y_rapport, /*pattern repeat in y-direction*/
double x_rapport_offset, /*offset of first plaid line*/
double y_rapport_offset, /*offset of first stripe line*/
int layer_type, /*layer type*/
int layer_type_length_option, /*option for length measuring*/
coordpt **holes, /*holes in the surface*/
int *holes_vertex_num, /*vertex numbers of the holes*/
int holes_num, /*number of holes in the surface*/
int product_type, /*type of product*/
int number_of_product_pieces, /*number of products*/
int marker_combi_type, /*type of stencil combination*/
double allowed_time, /*allowed processing time*/
double termination_yield, /*termination yield*/
int (*manual_interrupt)(), /*manual interrupt*/
int (*intermediate_solution)(), /*output of intermediate solutions*/
int (*error_message)(), /*output of error messages*/
nesting_constraint_type *constraints, /*placement constraints*/
int constraints_number, /*number of constraints*/
int *polygon_placed, /*return: polygon placed or not*/
double *x_translation, /*return: x-translations*/
double *y_translation, /*return: y-translations*/
double *rotation, /*return: rotations*/
int *flip, /*return: flip information*/
double *marker_length1, /*return: front marker length*/
double *marker_length2, /*return: back marker length*/
double *marker_yield, /*return: yield of the marker*/
int dump /*dump option*/
)
but from c# , we are importing this dll function as below
[DllImport("Test-T.dll", EntryPoint = "Test_Function", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
void Testing_Function(
ref coordpt[,] polygons,
ref int[] polygons_vertex_num,
ref double[] polygons_rotation_angle,
ref int []polygons_flip,
ref double []polygons_rotation_tolerance,
ref int []polygons_placement_group,
int polygons_num,
double surface_width,
double surface_pattern,
double x_rapport,
double y_rapport,
double x_rapport_offset,
double y_rapport_offset,
int layer_type,
int layer_type_length_option,
ref coordpt[,] holes, ref int[] holes_vertex_num,
int holes_num,
int product_type,
int number_of_product_pieces,
int marker_combi_type,
double allowed_time, double termination_yield,
ref int manual_interrupt,
ref int intermediate_solution,
ref int error_message,
ref Nesting_Constraint_Type[]constraints, int constraints_number,
ref int[] polygon_placed,
ref double[] x_translation,
ref double[] y_translation,
ref double[] rotation,
ref int[] flip,
ref double[] marker_length1,
ref double[] marker_length2,
ref double[] marker_yield,
int dump
);
and we calculated every parameter from c# and called the Testing_Function.
At called function (Testing_Function ),it is giving error as
AccessViolationException was Handled
---------------------------------------
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
plz help me out for this problem.
|
|
|
|
|
Hi, its me again, the n00b.
Last week i was doing a Image Explorer which manages around 1000 images per folder, its working fine and now i did ListView which shows it in large icon mode, the problem was when I tried to show the images, i resized the image, indexed it inside an image list and point the listviewitem to it. Ok then it works but its just slow, very slow, next step i did its to thumbnalize images to 96x96 and save them in a JPG to do a fast load without resize thinking that it will solve the problem. But it was slow like the other method, then I put a thread who gets a Queue of images to add into ImageList, but from my point of view it continues being slow. And then i thought maybe i need to ask ppl who knows better the .Net to show me wats the best way to load from HDD images into an image list.
Summary,
Im filling ListView pointing to a ImageList with a "Loading Image" Index 0, and put the images to load in a queue, then the other Thread gets the list and loads image doing some like:
Image = Image.FromFile( the file ); ImageList.Images.Add( Image ); And place the new Index into ListView...
Like i said, it works, but slow,
Somebody can give me some advice ?
Thanx in advance,
|
|
|
|
|
Hi, maybe you are running out of physical memory: loading a lot of images will soon cause Windows to fill all physical memory, and then to swap the images to disk again, which
is not only pointless but also often terribly slow.
When dealing with hundreds of images, make sure to only load thumbnail images, not entire images.
Furthermore, you may have to create small thumbnail files rather than trying to read them
from the original image files. The Image classes keep their files open (I guess to keep the
image properties available) for as long as the image object lives, hence consuming tons
of memory.
Or you may try the following: in one of my applications after reading an image from file,
I immediately copied the image into a new bitmap (see code snippet below), allowing
the gc to retrieve the original Image object immediately, just to avoid the file remaining open and a lot of memory being used.
Maybe you can do something similar ?
public Bitmap ReadImage(string fileSpec) {
FileStream stream=File.OpenRead(fileSpec);
Image image1=Image.FromStream(stream);
Bitmap image2=new Bitmap(image1);
stream.Close();
image1.Dispose();
return image2;
}
-- modified at 15:20 Monday 4th December, 2006
Luc Pattyn
|
|
|
|
|
mmmm, its faster but... like you said i have the images at disk thumbnalize 3kbytes per image at 32bits jpeg, also i put the imagelist in the same pixelformat, etc... and thats a simply loop that tooks 40-45secs loading 500images, memory its going to 48MB think is not the problem...
<br />
foreach (StockFile sfile in sf.Files)<br />
{<br />
string[] strItems = { sfile.FileName, sfile.Name };<br />
<br />
if ( File.Exists( sfile.SmallThumbFileName ) && indexItem<500 ) {<br />
<br />
FileStream stream = File.OpenRead(sfile.SmallThumbFileName);<br />
Image image1 = Image.FromStream(stream);<br />
ThumbWithFrame = new Bitmap(image1);<br />
stream.Close();<br />
image1.Dispose();<br />
fvImageList.Images.Add(ThumbWithFrame);<br />
<br />
lvFiles.Items.Add( new ListViewItem(strItems, fvImageList.Images.Count-1 ) );<br />
} else {<br />
DCRQueue dq = new DCRQueue();<br />
dq.sfile = sfile;<br />
dq.li = lvFiles.Items.Add( new ListViewItem(strItems, 0) );<br />
Thumbs2Do.Enqueue( dq );<br />
}<br />
<br />
indexItem++;<br />
}<br />
|
|
|
|
|
Hi Marcos,
I would suggest to temporarily remove the second halve of your for loop,
so you can observe the loading of the files, without the ListView and DCRQueue operations,
just to figure out which part is taking so long.
Is your ListView visible while your code executes ? maybe it recalculates everything
after adding each individual image, which I guess is not what you really need.
If so, you want to use a single AddRange outside the for loop instead of n times Add.
Alternatively, you may want to call SuspendLayout() and ResumeLayout() before/after the
for loop.
greetings,
Luc Pattyn
|
|
|
|
|
Think your are right right right, the problem is at ListView.Add... refatoring time...
Thanx for your time,
|
|
|
|
|
i just create one database it's:
create table HANGHOA
(
MAHANG varchar(9) not null,
TENHANG nvarchar(50) not null,
DVDOLUONG nvarchar(15) not null,
DINHLUONG int not null,
DONVI nvarchar(15) not null,
MOTA nvarchar(50) null ,
TONKHO int null ,
DGBAN int null ,
CANDUOI int null ,
constraint PK_HANGHOA primary key (MAHANG)
)
When i created datagrid and add TENHANG to col1 :
private void CreateDataGridStyle()
{
this.dataGrid1.ReadOnly=true;
DGStyle = new DataGridTableStyle();
DGStyle.MappingName ="HANGHOA";
col1 = new DataGridTextBoxColumn();
col1.MappingName ="TENHANG";
col1.HeaderText = "TH";
col1.Width = 90;
}
but now i want to create table TH with three MappingName : "HANGHOA";"DVDOLUONG";"DINHLUONG" to one.
Because when i create datagrid it's have 3 column but now i want to view it's one.
private void CreateDataGridStyle()
{
this.dataGrid1.ReadOnly=true;
DGStyle = new DataGridTableStyle();
DGStyle.MappingName ="HANGHOA"+"DINHLUONG"+"DVDOLUONG";
col1 = new DataGridTextBoxColumn();
col1.MappingName ="TENHANG";
col1.HeaderText = "TH";
col1.Width = 90;
}
ex: table first is
HANGHOA DVDOLUONG DINHLUONG
abc 1 st
but end is
"TableMapping"
abc is 1st
i said may be you can't understand but may be my "ex:" be you see the problem!
Thanks !!!Please Help me!
|
|
|
|
|
3. Keep the subject line brief, but descriptive. eg "File Serialization problem"
Please Help me!!!Thanks !!! may be brief but hardly descriptive.
only two letters away from being an asset
|
|
|
|
|
Your line:
DGStyle.MappingName ="HANGHOA"+"DINHLUONG"+"DVDOLUONG";
is equivalent to:
DGStyle.MappingName ="HANGHOADINHLUONGDVDOLUONG";
As there is no field by that name, it won't work.
You have to concatenate the values when you query the data from the database, not when you specify your data grid.
---
b { font-weight: normal; }
|
|
|
|
|
how can i add a autofilters like dropdownlist to a datagrid header ,and when
user selects one item from dropdownlist datagrid values must be updated.
thanks
mahesh.nalla
|
|
|
|
|
I am trying to pass an array of strings from C# to the .NET component
I created in Matlab. I am getting a compile time error in Visual
Studio telling me that it can't convert a string array to a MWArray.
I have tried performing explicit conversions, but none of them work.
Any help would be greatly appreciated.
Here is an example of what I am trying to do:
[C#]
using MathWorks.MATLAB.NET.Arrays;
using MyMatlabNet;
...
MyMatlabNetClass myclass = new MyMatlabNetClass();
...
string [] mydata;
myclass.somemethod(mydata);
I have tried (MWArray), (MWCharArray), (MWCellArray) and nothing
works (allows it to compile).
|
|
|
|
|
Hello all... If you had a parent object and wanted to expose its children from persistent storage, would you do it by exposing the children as if the parent was a List or just a few methods for getting the count and a range of child objects... or is there another method I might not be aware of.
The children must be editable and retain their data in persistent storage. There could be thousands of children as well.
Secondly, if you were to have a function that did something like "Take money from parent and give to child" would you put this function on the parent, child or as a static function?
|
|
|
|
|
If you are using .NET 2, then I would look at generic collections to store your items:
public class Parent
{
List<Child> _children = new List<Child>();
public int Add(Child value)
{
_children.Add(value);
}
public void LoadAll()
{
}
public void Save()
{
foreach (Child child in _children)
{
child.Save();
}
}
}
public class Child
{
public void Save()
{
}
public static Child Fill(IDataRecord row)
{
Child child = new Child();
child.Id = Convert.ToInt32(row["Id"].ToString());
return child;
}
}
This is just a sample of the type of approach you might take. It isn't intended to be directly coded from.
-- modified at 4:37 Tuesday 5th December, 2006
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|
|