|
I'm using primitive types (int s). Actually I'm implementing multi-column sorting for a list view control (it will come as a CP article ) and I have to keep track of all columns clicked by the user. If the user clicks one column, clicks another one, and then click the first again, I have to remove it from the list and add it again at the end. Also if the user clicks twice in a row the same column, I have to togle its sign (indicating descending order.)
So, when I create a comparer object to set the ListViewSorter (or something like that) property, I pass this ArrayList as a parameter, and each time Compare is called to compare two items, I have to compare the items according to the columns in the order they are in the ArrayList . Bsically I used a foreach(int i in ArrayList) and compared the subitems in column i , and if they were the same, checked the next column.
After your first suggestion, in the constructor I converted the ArrayList to a regular array, and the same code (measured with a profiler) runs about 18% faster.
Wyxlwiis wrote:
Hopfully im not waisting your time with my suggestion
Not at all. I appreciate it very much. Thanks!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
What you need to do any better is Visual Studio 2005 and CLR 2.0. That gives you typed arrays which do not do boxing or downcasting.
There are 10 kinds of people in the world.
Those that read binary...
...and those who don't.
|
|
|
|
|
I'm using DataBinding to create a software. I use wizard to create many data form. How I can reuse OleDbConnection to create one and use it in many form that i can still using wizard with OleDbDataAdapter.
Nothing
|
|
|
|
|
In your database layer ( you DO have a seperate class for database access, right ? ) put your connection as a private variable, then again as a private property. All functions should use the property, which initialises on the first go, then returns the existing connection. Impliment IDisposable and a finaliser to make sure that the connection is let go when your app closes.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi everyone,
I'm writing a BalloonNotifyIcon component, which just like a NotifyIcon control but can display ballon tips by calling insider methods. Since I can inherit from NotifyIcon control, I have to write and deal with all the events myself.
Now I have program with dealing all the events of my BalloonNotifyIcon, because the componet doesn't has a WndProc procedure to override. And I cann't even show the ContextMenu when a user right-click the notify icon.
I cann't let my componet receive any messages or raise any events.
The events I want to deal with as follows(all declared, but don't know how to raise):
Click : When a user Left-Click the notify icon.
DoubleClick : When a usser dounle-click the notify icon with either mouse button.
MouseDown : When a user press a mouse button on the notify icon.
MouseUp : When a user release a mouse button on the notify icon.
BalloonTipShow : When the balloon tip displays by ShowTip method.
BalloonTipHide : When the balloon tip icon is deleted.
BalloonTipClick : When a user click the balloon tip.
BalloonTipTimeout: When the balloon tip disappears as a result of timeout.
Will anyone please tell me how to do?
Codes that doesn't work(the procedure of WndProc never run);
public class BalloonNotifyIcon : System.ComponentModel.Component{
...
...
protected int WndProc (IntPtr hwnd,int m,IntPtr wParam, IntPtr lParam) {
int ret=0;
BalloonMessages bm=(BalloonMessages)m;
switch(bm){
case(BalloonMessages.SHOW):
Debug.WriteLine("ShowIcon");
OnBalloonTipShow(new System.EventArgs());
break;
case(BalloonMessages.HIDE):
OnBalloonTipHide(new System.EventArgs());
break;
case(BalloonMessages.TIMEOUT):
OnBalloonTipTimeout(new System.EventArgs());
break;
case(BalloonMessages.USERCLICK):
OnBalloonTipClick(new System.EventArgs());
break;
...
deal with mouse up/down message to raise events.
...
default:
ret = DefWindowProc(hwnd, m, wParam, lParam);
break;
}
return ret;
}
...
Property declarations.
...
} OnClick(new EventArgs());
downedL=false;
}else{
OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, MousePostion.X, MousePostion.Y, 0));
downedL=false;
}
break;
case(BalloonMessages.MBUTTONDBLCLK):
OnDoubleClick(new MouseEventArgs(MouseButtons.Middle ,2,MousePostion.X, MousePostion.Y, 0));
break;
case(BalloonMessages.MBUTTONDOWN):
downedM=true;
OnMouseDown(new MouseEventArgs(MouseButtons.Middle, 0, MousePostion.X, MousePostion.Y, 0));
break;
case(BalloonMessages.MBUTTONUP):
if(downedM){
OnClick(new EventArgs());
downedM=false;
}else{
OnMouseUp(new MouseEventArgs(MouseButtons.Middle, 1, MousePostion.X, MousePostion.Y, 0));
downedM=false;
}
break;
case(BalloonMessages.RBUTTONDBLCLK):
OnDoubleClick(new MouseEventArgs(MouseButtons.Right ,2,MousePostion.X, MousePostion.Y, 0));
break;
case(BalloonMessages.RBUTTONDOWN):
downedR=true;
OnMouseDown(new MouseEventArgs(MouseButtons.Right, 0, MousePostion.X, MousePostion.Y, 0));
break;
case(BalloonMessages.RBUTTONUP):
if(downedR){
OnClick(new EventArgs());
downedR=false;
}else{
OnMouseUp(new MouseEventArgs(MouseButtons.Right, 1, MousePostion.X, MousePostion.Y, 0));
downedR=false;
}
break;
default:
ret = DefWindowProc(hwnd, m, wParam, lParam);
break;
}
return ret;
}
...
Property declarations.
...
}
E-mail: zc_djx@hotmail.com
I'm learning VB.Net & C#, you are always welcome to help me!
|
|
|
|
|
Inherit from NativeWindow instead.
Alomgir Miah
Live Life King Size
|
|
|
|
|
Well, it's ok if inherit from NativeWindow.
Now my solution is overrides the WndProc of the parent Form, then call a public method of my compenent, which calls the protected WndProc method wrote by myself, then call base.WndProc in the parent Form's WndProc method.
Now I have another problem: HOW TO deal with MouseLeave event? I don't know work out whether the mouse is out of the region of my Notify Icon.
E-mail: zc_djx@hotmail.com
I'm learning VB.Net & C#, you are always welcome to help me!
|
|
|
|
|
I dont know if this helps
Sample class
Private Class MyListener
Inherits NativeWindow
Public Event MyMouseMove(ByVal sender As Object, ByVal e As EventArgs)
Const WM_MOUSEMOVE = &H200
Private ctrl As Control
Public Sub New(ByVal ctrl As Control)
AssignHandle(ctrl.Handle)
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
' Listen for operating system messages
If m.Msg = WM_MOUSEMOVE Then
RaiseEvent MyMouseMove(ctrl, New EventArgs)
End If
MyBase.WndProc(m)
End Sub
Protected Overrides Sub Finalize()
ReleaseHandle()
MyBase.Finalize()
End Sub
End Class
How to use
Dim WithEvents sl As MyListener
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
sl = New MyListener(TextBox1)
End Sub
Private Sub sl_MyMouseMove(ByVal sender As Object, ByVal e As
System.EventArgs) Handles sl.MyMouseMove
Me.Text = "My Mouse Move"
End Sub
Thanks
Alomgir Mih
Live Live King Size
|
|
|
|
|
using System;
using System.Collections;
using System.Configuration;
namespace Samples
{
class Demo
{
public static void Main()
{
IDictionary sampleTable = (IDictionary) ConfigurationSettings.GetConfig("customSection");
Console.WriteLine("First is: {0}, second is: {1}, third is: {2}",
sampleTable["setting1"],
sampleTable["setting2"],
sampleTable["setting3"]);
}
}
}
and the configuration file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="customSection" type="System.Configuration.SingleTagSectionHandler" />
<section name="" type=""></section>
</configSections>
<customSection setting1="some value" setting2="value two" setting3="third value" />
</configuration>
Can someone help me rectify the problem on why they say object reference is not set to an instance of an object.
|
|
|
|
|
Are you sure your configuration file syntax is correct?
I haven't used them myself (in fact, I happen to hate the xml config files :p) but it sounds to me like your customSection dictionary is not being found.
|
|
|
|
|
If that is the case, then something must be wrong with the examples in the books. LOL
|
|
|
|
|
How can I programmatically determine whether a text in a listview column is longer than the column's width (i.e. displayed partially and ends with ellipsis)?
Thanks!
|
|
|
|
|
Try this
protected virtual void GenericListControlMouseMove(object sender, MouseEventArgs e)
{
Point ptOnlist = Point.Empty;
ListViewItem item = null;
int subItemIndex = -1;
int subItemTextWidth = -1;
ListViewItem.ListViewSubItem curSubItem = null;
try
{
//
/// Check if no mouse button is down
//
if (e.Button == MouseButtons.None)
{
item = this.GetItemAt(e.X, e.Y);
if (item != null)
{
subItemIndex = this.GetSubItemIndexFromPoint(item, new Point(e.X, e.Y));
if (subItemIndex != -1)
{
//
/// Get the subItem on which the mouse pointer is present
//
curSubItem = item.SubItems[subItemIndex];
if (curSubItem != null)
{
if (curSubItem.Text.Length > 0)
{
subItemTextWidth = this.ListViewGetStringWidth(curSubItem.Text);
if (subItemTextWidth != -1)
{
//
/// MSDN:: ListViewSubItem text is padded 6 pixels on both side of the Text
//
subItemTextWidth += LISTVIEWSUBITEM_STRING_PADDING;
if (subItemTextWidth > this.Columns[subItemIndex].Width)
{
if (curSubItem != this.lastSubItemHovered)
{
this.SetToolTipText(curSubItem.Text);
this.lastSubItemHovered = curSubItem;
}
}
else
{
this.SetToolTipText(string.Empty);
}
}//end subItemTextWidth
}//end curSubItem.Text
}//end curSubItem
}//end subItemIndex
}//end item
}//end e.Button
}
catch (Exception exception)
{
ExceptionDisplayer exceptionDisplayer = new ExceptionDisplayer(exception);
}
}
protected int ListViewGetStringWidth(string subItemText)
{
IntPtr hString = Marshal.StringToHGlobalAuto(subItemText);
int width = UnsafeNativeMethods.SendMessage(this.Handle, LVM_GETSTRINGWIDTHW, 0, hString);
Marshal.FreeHGlobal(hString);
return width;
}
Live Life King Size
Alomgir Miah
|
|
|
|
|
|
I'm just starting to learn about signing and my assemblies. I have two assemblies - dlls - written in C#. A.dll references B.dll - both mine. I'm attempting to add a strong name to A.dll - I've used "sn -k A.snk" and in Assembly.info set the AssemblyKeyFile to "A.snk". When I try to build A I get an error:
Assembly generation failed -- Referenced assembly 'B' does not have a strong name
Do all of my assemblies have to use strong names if they are referenced from another assembly that is using strong names?
|
|
|
|
|
dirkhelmet!@yahoo.com wrote:
Do all of my assemblies have to use strong names if they are referenced from another assembly that is using strong names?
Any strong-named assembly can reference only other strong named assemblies, so, yes you must give b.dll a strong name as well.
Absolute faith corrupts as absolutely as absolute power
Eric Hoffer
All that is necessary for the triumph of evil is that good men do nothing.
Edmund Burke
|
|
|
|
|
Hi experts ,
I am faceing a exception in my Socket programm.
I am created a TCPListner() and it it wait's for TcpClient() request.
After connecting server to client i am sending some txt file content as String through NetWork stream to client. Again When Client Disconnect, it send some same file content after modification to server .
Now When i am closing the Server , I get a WSACancelBlocking Exception.
I am Giving Some Code What i am doing in server and Client :
Server ()
{
using namespace System.net.socket ;
-----
----
DoListen()
{
listener = new TcpListener(PORT_NUM);
listener->Start();
Byte bytes[] = new Byte[10000];
String* m_sdata = 0;
While (true)
{
UserConnection *client = new UserConnection(listener->AcceptTcpClient());
__hook(&UserConnection::LineReceived, client, OnLineReceived);
}//End of while(true);
}
}/* end of server */
Client()
{
Byte data[] = new Byte[1200]
Byte data1[] = new Byte[1200];
Int32 port = 10000;
//writting data to Stream.
}
Now When i close the Server File i got two Exception
1. ASCII Encodding Exception
2. WSA CancelBlocking CAll Exception.
Please i need the Solution for this.
Please help me..
sukanta
|
|
|
|
|
hi,
i want to make a program that draw equations.
the first thing needed is to evaluate the expression.
i used the stack to make infix to postfix conversion, but the problem here is in
the priority how can i implement the priority with out forcing the user to write every
operation between brackets ???????
any help please
thanx in advance
|
|
|
|
|
It's pretty simple actually, create an operator stack and push operators into them depending on priority. The algorithm looks like
For each element in the expression
1. If current element in expression is a number, print it out.
2. If current element in expression is an operator
a. If stack is empty, push operator into stack.
b. else, if current operator has greater precedence than operator at the top of the stack, push the current operator also into the stack.
c. else, pop operator at the top of the stack and print it
Print out contents of the stack.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
thnx for ur help ,i will try this
|
|
|
|
|
You ca also create a block of C# code with a static function that returns the value of the expression, such as 'return (12 * 25 + System.Math.Sin(System.Math.PI));', and compile it on-the-fly in a memory assembly, then call the method and obtain the result. Try this article:
DotNetCompiler
It is in VB.NET, but i'm sure you won't have problems...
|
|
|
|
|
Hello All,
I have added a bool check column to Datagrid.but i dont know how would i come to know that whether that checkbox is selected or not because depending on that checkbox value i have to change value in another column?
|
|
|
|
|
Hi amrutajoshi,
Probably this may help you
foreach(DataGridItem childItem in myGrid.Items)
{
CheckBox myBox = (CheckBox) childItem.FindControl("MSChecked");
if(myBox != null && myBox.checked)
{
Response.Write("Checked");
}
}
Srinivas
|
|
|
|
|
Well i dont know if the datagrid is in Web or Forms ?.
But if it is in Web do you want it clientside or serverside ?.
If Serverside its very simple
your CheckBox has a OnChangedEvent create a method and call it from there
asp:CheckBox OnCheckedChanged="doWork" id="myCheckBox" runat="server">
|
|
|
|
|
I'm doing some interop and passing a structure to managed code via an IntPtr.
I convert the structure to the IntPtr as follows, in a mixed-mode C++ program, which then passes it to the C# program:
System::IntPtr func(Event &e)<br />
{<br />
return __nogc new System::IntPtr(&e);<br />
}
I'm not too confident about my mixed-mode C++ skills, but I think that's right... right?
However, the data I get back from PtrToStructure gives me complete gibberish. It's not a member alignment problem either, because the data is supposed to be mostly nulls but I get numbers in the millions (Event contains mostly pointers to other structures).
What am I doing wrong?
|
|
|
|
|