|
Hello,
I've wrote UserControl where one of properties is collection. Item of collection is object of type GroupClass. Code below:
[Serializable]
public class GroupClass
{
private string pGrpupName;
private Control pGroupControl;
[Category("Group")]
[Description("Definition")]
public string GroupName
{
get { return pGrpupName; }
set { pGrpupName = value; }
}
[Category("Group")]
[Description("Definition")]
[Browsable(false)]
public Control GroupControl
{
get { return pGroupControl; }
set { pGroupControl = value; }
}
}
And after when I add item to collection also groupbox should show on UC. I've override some methods in my Collection. It works. But it doesn't when I try to remove item in designer. Groupbox is still there and method RemoveItem doesn't works
public class WRListClass<T> : Collection<T>
{
public event EventHandler<ItemInsertedArgs<T>> BeforeItemInserted;
public event EventHandler<ItemRemovedArgs<T>> BeforeItemRemoved;
public event EventHandler<ItemSetArgs<T>> BeforeItemSet;
public event EventHandler<ItemInsertedArgs<T>> AfterItemInserted;
public event EventHandler<ItemRemovedArgs<T>> AfterItemRemoved;
public event EventHandler<ItemSetArgs<T>> AfterItemSet;
public event EventHandler ListChanged;
protected override void InsertItem(int index, T item)
{
EventHandler<ItemInsertedArgs<T>> beforehandler = BeforeItemInserted;
EventHandler<ItemInsertedArgs<T>> afterhandler = AfterItemInserted;
EventHandler handlerListChanged = ListChanged;
if (beforehandler != null)
{
beforehandler(this, new ItemInsertedArgs<T>(index, item));
}
base.InsertItem(index, item);
if (afterhandler != null)
{
afterhandler(this, new ItemInsertedArgs<T>(index, item));
}
if (handlerListChanged != null)
{
handlerListChanged(this, null);
}
}
public new bool Remove(T item)
{
return base.Remove(item);
}
public new void RemoveAt(int index)
{
base.RemoveAt(index);
}
protected override void RemoveItem(int index)
{
EventHandler<ItemRemovedArgs<T>> beforehandler = BeforeItemRemoved;
EventHandler<ItemRemovedArgs<T>> afterhandler = AfterItemRemoved;
EventHandler handlerListChanged = ListChanged;
T item = default(T);
if (index >= 0)
item = this[index];
WRListClass<T> old = this;
if (beforehandler != null)
{
beforehandler(this, new ItemRemovedArgs<T>(index, item));
}
base.RemoveItem(index);
if (afterhandler != null)
{
afterhandler(this, new ItemRemovedArgs<T>(index, item));
}
if (handlerListChanged != null)
{
if (old != this)
handlerListChanged(this, null);
}
}
protected override void SetItem(int index, T item)
{
EventHandler<ItemSetArgs<T>> beforehandler = BeforeItemSet;
EventHandler<ItemSetArgs<T>> afterhandler = AfterItemSet;
EventHandler handlerListChanged = ListChanged;
WRListClass<T> old = this;
if (beforehandler != null)
{
beforehandler(this, new ItemSetArgs<T>(index, item));
}
base.SetItem(index, item);
if (afterhandler != null)
{
afterhandler(this, new ItemSetArgs<T>(index, item));
}
if (handlerListChanged != null)
{
if (old != this)
handlerListChanged(this, null);
}
}
}
public class ItemInsertedArgs<T> : EventArgs
{
public int Index;
public T Item;
public ItemInsertedArgs(int index, T item)
{
this.Index = index;
this.Item = item;
}
}
public class ItemSetArgs<T> : EventArgs
{
public int Index;
public T Item;
public ItemSetArgs(int index, T item)
{
this.Index = index;
this.Item = item;
}
}
public class ItemRemovedArgs<T> : EventArgs
{
public int Index;
public T Item;
public ItemRemovedArgs(int index, T item)
{
this.Index = index;
this.Item = item;
}
}
----USERCONTROL
[Designer("System.Windows.Forms.Design.ParentControlDesigner", "IDesigner")]
public partial class UserControl1 : UserControl
{
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Content)]
private WRListClass<GroupClass> pGroups = new WRListClass<GroupClass>();
public UserControl1()
{
InitializeComponent();
pGroups.AfterItemInserted += new EventHandler<ItemInsertedArgs<GroupClass>>(pGroups_AfterItemInserted);
pGroups.BeforeItemRemoved += new EventHandler<ItemRemovedArgs<GroupClass>>(pGroups_BeforeItemRemoved);
}
void pGroups_BeforeItemRemoved(object sender, ItemRemovedArgs<GroupClass> e)
{
if (e != null)
{
if (e.Item != null)
{
if (e.Item.GroupName != null)
{
if (e.Item.GroupName.Trim() != "")
{
if (e.Item.GroupControl != null)
{
e.Item.GroupControl.Parent = null;
this.Controls.Remove(e.Item.GroupControl);
e.Item.GroupControl.Dispose();
}
}
}
}
}
}
void pGroups_AfterItemInserted(object sender, ItemInsertedArgs<GroupClass> e)
{
if (e != null)
{
if (e.Item != null)
{
if (e.Item.GroupName != null)
{
if (e.Item.GroupName.Trim() != "")
{
if (e.Item.GroupControl == null)
{
e.Item.GroupControl = new GroupBox();
e.Item.GroupControl.TabIndex = pGroups.Count + 1;
e.Item.GroupControl.Text = e.Item.GroupName;
e.Item.GroupControl.Name = e.Item.ToString();
e.Item.GroupControl.Parent = this;
this.Controls.Add(e.Item.GroupControl);
e.Item.GroupControl.Dock = DockStyle.Top;
e.Item.GroupControl.BringToFront();
}
}
}
}
}
}
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Content)]
[EditorAttribute(typeof(System.ComponentModel.Design.CollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
public WRListClass<GroupClass> Groups
{
get { return pGroups; }
set {
pGroups = value;
}
}
}
Please help! Thanks!
|
|
|
|
|
I'm not going to bother reading that badly formatted code dump because:
1) because it is badly formatted
2) there is too much of it even if it were correctly formatted.
Solution:
1) cut out anything that is not relevant to the problem.
2) surround the remaining code with 'pre' tags and format it properly
You do not ask a question. What is it that you want to know?
Read this[^], before editing your original post. Pay particular attention to items 2, 4, 5 and 7.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
hi pls i need information on any biometric sdk/dll like the GrFinger that i can use to access the biometric features of an hp ipaq pda,or any pda and the compatible dll/sdk .all shld be .net compatible
i can do all things........
|
|
|
|
|
solomonope wrote: i can do all things........
except search Google ...
|
|
|
|
|
I've made a small app that downloads an XML file every one minute from a server. I have to use a Socket for it as I must write the HTTP headers myself.
The program works fine until it doesn't. Every few minutes the XML that's being downloaded is somewhat corrupt. When I open it I can see the XML with all the normal data, except that in random places there are always 4 random characters that are being inserted. When I use a packet sniffer I can see that the data being received is fine and that the chars aren't in the end or beginning of a packet - just in random places.
This is the loop I'm using to read the XML file:
file = File.Create("C:\\info.xml");
bool isFirstPacket = true;
byte[] buffer = new byte[1024];
int bytesRead;
while (true)
{
bytesRead = stream.Read(buffer, 0, 1024);
if (bytesRead == 0)
continue;
if (isFirstPacket)
{
isFirstPacket = false;
int i = 0;
while (buffer[i] != 0x3c)
{
i++;
}
file.Write(buffer, i, bytesRead - i);
}
else if (buffer[bytesRead - 2] == 0x0d && buffer[bytesRead - 1] == 0x0a && buffer[bytesRead - 3] == 0x0a && buffer[bytesRead - 4] == 0x0d && buffer[bytesRead - 5] == 0x30)
{
file.Write(buffer, 0, bytesRead - 7);
file.Close();
break;
}
else
{
file.Write(buffer, 0, bytesRead);
}
}
file.Close();
Does anyone have a clue as to why this would happen? thanks.
|
|
|
|
|
I can't see anything that jumps out at me, apart from the possibility that you could be addressing a non-vaid location in the else if clause. If bytesRead is less than 5 at this point you could have a problem. Also in this clause you have file.Write(buffer, 0, bytesRead - 7); - should that be 7 or 5?
My only suggestion would be to run it through the debugger and try to see what's going on.
|
|
|
|
|
Thanks for the reply.
The else if works as it should, though you're right I should see if bytesRead is bigger than 5, the reason for the "-7" is some added spaces at the end of the XML.
As I go though the trace and look at the buffers I see these chars inserted in them, I get them through the NetworkStream.Read and still the network sniffer shows a "clear" packet. Odd.
|
|
|
|
|
Hello all of you,
I made a webservice and I can't get this to run via proxy.
the basic procedure on the client side looks like this:
MyWebservice service = new MyWebservice();
WebProxy iProxy = new WebProxy(_proxyAdress, true);
service.Proxy = iProxy;
...
if(service.LogOn(user, pass))
{
...
data = service.GetMyData();
now what happens is that the session variables are lost on the GetMyData() call
on the server side:
[WebMethod (EnableSession = true)]
public bool Logon(string s, string p)
{
...
Context.Session.Add ("LoggedIn", true);
...
return
}
[WebMethod (EnableSession = true)]
public SomeData GetMyData()
{
...
if(Context.Session ["LoggedIn"])
...
}
Whitout proxy it goes but with proxy dosen't. Please drop some tips if you have some. Thx.
|
|
|
|
|
Have you tried regenerating the proxy?
CCC solved so far: 2 (including a Hard One!)
|
|
|
|
|
Yes I did, thx for the tip
|
|
|
|
|
I suppose you need to attach CookieContainer to your web service instance using CookieContainer property of SoapHttpClientProtocol class.
service.CookieContainer=new System.Net.CookieContainer();
Read here more about Session and web methods.
Life is a stage and we are all actors!
|
|
|
|
|
I use cookie container, thx for the response...
|
|
|
|
|
Hi all,
Is there a way to open a named browser window from a windows application.
From ASP.NET i used javascript's "window.open(url,name)", is there some way i can achieve the same result from a windows application.
I tried some things with the System.Diagnostics.Process.Start(), but i don't know if it is possible to give the name for the new window in the parameters (if it is possible, i don't know how )..
Any ideas?
Thanks in advance.
|
|
|
|
|
do
{
iniText = iniStream.ReadLine();
if(String.Compare(iniText.Substring(0,1),("*")) == 0)
continue;
string [] dataItems = iniText.Split(new Char [] {','});
dataGridView1.Rows.Add(dataItems);
} while (iniText != null);
When stepping through the code, dataItems correctly contains each array of comma separated variables, but the datagrid control is not being populated with the Rows.Add method. What am I missing?
t.i.a
OK, I changed it to this
do
{
iniText = iniStream.ReadLine();
if (iniText == null)
continue;
if(String.Compare(iniText.Substring(0,1),("*")) == 0)
continue;
string [] dataItems = iniText.Split(new Char [] {','});
dataGridView1.Rows.Add(dataItems);
} while (iniText != null);
obviously I need to rethink my loop logic. But when i step through in Debug with F5 it populates the control properly, when I run without debugging, it is still empty. Why does that happen?
modified on Wednesday, October 14, 2009 2:42 AM
|
|
|
|
|
I agree your loop logic needs some work, but in both original form and the modified form below it works fine either debugged or run as release version.
Without seeing the rest of your code, I can only assume the difference is path related - is the file you are reading relative to the debug code folder and thus not available in the release version?
string[] lines = File.ReadAllLines(@"C:\XXTemp\new.txt");
foreach (string line in lines)
{
if (!line.StartsWith("*"))
{
dataGridView1.Rows.Add(line.Split(','));
}
}
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Thanks. Of course, that is exactly what it was, I hadn't changed the file read section to allow the user to browse for an actual file location!
doh! thanks for the heads up
|
|
|
|
|
Hi,
I want to write some data to an excel sheet. If it is open, then write to the same excel sheet, if not open, then open the excel sheet and perform operations.
I dont know how to get control of the open excel sheet.
Here is my code:
//check if the worksheet is already open.
try
{
using (FileStream fs = File.Open(txtBx_worksheetPath.Text, FileMode.Open))
{
if(fs == null)
{
theWorkbook = ExcelObj.Workbooks.Open(txtBx_worksheetPath.Text, 0, false, 5,
System.Reflection.Missing.Value, System.Reflection.Missing.Value, false, Excel.XlPlatform.xlWindows,"\t", true, false, 0, true, false, System.Reflection.Missing.Value);
}
}
}
catch(Exception)
{
// activate excel sheet
// theWorkbook.Activate();
}
Now, if the file is already open, then it performs nothing.
I dont want to close the excel sheet and reopen it.
Please help me.
Thanks
Ananya
|
|
|
|
|
I am working with World of Warcraft and C#. In WOW there is no way to send data out to another app nor are you allowed to use Spy++ to read data from WOW. A though occurred to me to simply create an Addon that draws a series of colored boxes near the top of the screen away from any that would get in the way of the users use of WOW. These colored boxes would represent a value I would read in via C# screen area capture. My question is, is this the best way to go about something like this or is there a better way?
|
|
|
|
|
I read an article here on CodeProject that used 3 programs to have Source Control in Visual Studio.
VisualSVN Server
TortoiseSVN
AnkhSVN
They all seem to do the job, and they all seem to do so fairly easily. I am wanting to use this just so I can host my personal project code on a server and not have to carry the code on a flash drive anymore (it is very unsettling to do so).
My question is has anymore used these before and can give a good review on them, OR does anyone have an idea of one that might fit a little better for my needs? I am just trying to store all my code(i.e. personal use) on a server with simple versioning, and access to the code from multiple laptops/desktops ect.
Thanks for any and all help, and I am positive that this is in the wrong forum, not sure where it goes, I used to post these kinds of questions in the Lounge, but it says no programming questions, and I don't want to put this in one of the more-or-less dead forums.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
I got anxious and continued to do research while I waited for an answer. The only one I kept seeing over and over was VisualSVN, so I setup the server, installed the client, and it made me download TortoiseSVN. I don't need the 3rd one.
I have been playing around with it using my desktop, and laptop, and so far, I am loving it.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Good things come to those who wait, and do their own research
only two letters away from being an asset
|
|
|
|
|
I'm using this and it works very well. Looks & feels like VSS 6.
It's free for single user.
Everything makes sense in someone's mind
|
|
|
|
|
|
Why do you have to use LINQ ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
hi,
business requirement.
thanks
|
|
|
|
|