|
I had this idea of creating altogether a new form from scratch and putting the current datagrid where i intended to in the new form. Thanks for the idea. Man its lot of work. Believe me each and every step is mystery in .NET.
Srinivas
|
|
|
|
|
Hey,
The button is working now after i created a new form an copy and pasted each bit of code. It redirects to a new page.
Thanks very much
Srinivas
|
|
|
|
|
Srinivas Jonnalagadda wrote:
Man its lot of work. Believe me each and every step is mystery in .NET.
It's a learning curve, your best best is to not mess with any traditional HTML, just use the .NET server controls, and don't add any forms.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hello,
I need a collection that works much like ArrayList , dynamically sizable, allowing me to add and remove items, either at the end or in the middle.
The problem with an ArrayList is that it causes boxing/unboxing of the value types, and this degrades performance. A simple array is not dynamically sizable.
Any ideas? For the moment I'm stuck with ArrayList , but I'd like to know if there's something better.
Thanks,
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
maybe your looking for a hashtable?
|
|
|
|
|
Well i dont know if this will solve your problem, depends on how often you add to the list.
But if you read the list often more rarely changeing its size
you could use the ArrayList.ToArray() method
it works this way
struct MyStruct
{
public string name;
public string age;
}
public class WebForm6 : System.Web.UI.Page
{
ArrayList list = new ArrayList();
private void Page_Load(object sender, System.EventArgs e)
{
MyStruct s = new MyStruct();
s.name = "firstPerson";
s.age = "45";
list.Add(s);
s = new MyStruct();
s.name = "secondPerson";
s.age = "27";
list.Add(s);
MyStruct[] sArray = (MyStruct[])list.ToArray(typeof(MyStruct));
Response.Write(list.Count + " list.Count ");
Response.Write(sArray.Length + " sArray.Length ");
Response.Write(sArray[0].name + " sArray.name ");
Response.Write(sArray[1].name + " sArray.name ");
Response.Write(sArray[0].age + " sArray.age ");
Response.Write(sArray[1].age + " sArray.age ");
list = new ArrayList(sArray);
s = new MyStruct();
s.name = "thirdPerson";
s.age = "15";
list.Add(s);
sArray = (MyStruct[])list.ToArray(typeof(MyStruct));
Response.Write(list.Count + " list.Count ");
Response.Write(sArray.Length + " sArray.Length ");
Response.Write(sArray[0].name + " sArray.name ");
Response.Write(sArray[1].name + " sArray.name ");
Response.Write(sArray[2].name + " sArray.name ");
Response.Write(sArray[0].age + " sArray.age ");
Response.Write(sArray[1].age + " sArray.age ");
Response.Write(sArray[2].age + " sArray.age ");
}
I know there it takes a bit work for the cpu to convert back and forth when adding and removing items
but you'll have all methods of an arraylist when editing the content of your Array
and you can access the variables or properties without unboxing every time you read from the aray
Hope this helps
|
|
|
|
|
I think this might work. It's not the complete solution I'm looking for, but this might improve performace a little. I only add items to the ArrayList on user actions, so it's not that much of a problem. But then I use them for sorting, and with many items, the unboxing can become slow.
I'll keep looking into it, but thanks for the pointer!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Luis Alonso Ramos wrote:
The problem with an ArrayList is that it causes boxing/unboxing of the value types, and this degrades performance. A simple array is not dynamically sizable
Generics .
ArrayList is array... on power-ups. Judging by operations you need (add/remove) you can have growable array - array that doubles (allocate new array + move all items ) it's size everytime it is full. That is how ArrayList internaly works, too.
David
"Stay Kul And Happy" I.A.
|
|
|
|
|
dnh wrote:
Judging by operations you need (add/remove) you can have growable array
I also need insert. I think it could be implemented more or less like a linked list, but then it complicates everything.
For now, I was doing a foreach(int i in ArrayList) in every comparison. I changed the comparer object to get a real array in the constuctor, and do the foreach(int i in array) and it speeded things up by 18%.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
I dont know if you are using primitive value types or structs.
But if you use struct you could implement the Icomparable in the struct, and thereby avoid boxing and unboxing when sorting
struct MyStruct : System.IComparable
{
public string name;
public int age;
public static enuSortOrder mySortOrder;
public static enuSortOrder SortOrder
{
get
{
return mySortOrder;
}
set
{
mySortOrder = value;
}
}
public enum enuSortOrder
{
Name,Age
}
public int CompareTo(object obj)
{
switch (mySortOrder)
{
case (enuSortOrder)enuSortOrder.Name:
{
string x = this.name;
string y = ((MyStruct)obj).name; // DESC
return x.CompareTo(y);
}
case (enuSortOrder)enuSortOrder.Age: //DESC
{
int x = this.age;
int y = ((MyStruct)obj).age;
return x.CompareTo(y);
}
default: break;
}
return 0;
}
public override string ToString()
{
return "Name: " +this.name + "Age:" + this.age;
}
}
public class WebForm6 : System.Web.UI.Page
{
ArrayList list = new ArrayList();
private void Page_Load(object sender, System.EventArgs e)
{
MyStruct s = new MyStruct();
s = new MyStruct();
s.name = "secondPerson";
s.age = 27;
list.Add(s);
s.name = "firstPerson";
s.age = 45;
list.Add(s);
Response.Write(list.Count + " list.Count ");
Response.Write(((MyStruct)list[0]).ToString() + " Unsorted ");
MyStruct.SortOrder = MyStruct.enuSortOrder.Name;
list.Sort();
Response.Write(list.Count + " list.Count ");
Response.Write(((MyStruct)list[0]).ToString() + " Sorted ");
}
just add more variables in the enum and conditions in the swicth like NameASC,AgeASC and so on
Hopfully im not waisting your time with my suggestion
|
|
|
|
|
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?
|
|
|
|
|