|
You have broken Forum, if you can edid, edid part that uses <>. I recomend when you pasting use option: "Encode "<" (and other HTML) characters when pasting".
For the actual code, please use PRE tags, so that is more readable
|
|
|
|
|
Please contact the hamsters (via the site bugs and suggestions forum) to let them know what you did to break the forum: I am sure they will want to make sure it can't happen again! You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
This page cam be easly costumized with HTML tags. tag like </td> can realy break forum
|
|
|
|
|
Should it be the PostBack of iBtnAddRow that generates all the code again! Try saving the table in a Session or a ViewState! and after every postback return it back!
like
protected void iBtnAddRow_Click(object sender, ImageClickEventArgs e)
{
Session["YourTable"] = tblLoanTypes;
}
private void Page_Load(
{
tbl_LoanTypes = (HtmlTable)Session["YourTable"];
}
|
|
|
|
|
Thanks for the reply mate! I'll give it a try and see how it goes though I am sure that it might not be a good idea saving the table in the session as this is a high traffic site and people can have more than 10 rows in their table. So the table times the number of users may make the site perform slow. Nonetheless, I will carry out an SVT and see how it goes.
Regards.
|
|
|
|
|
I am looking for a way to open a eml file and save it to an image format like a multi page tif. Also I need a way to check if it has an attachment and then save its attachment also.
|
|
|
|
|
I have a customized ComboBox and a class with many properties. I am putting one of my ComboBoxes on my MainForm for each property in my class. When it’s time to “run” my application I need to transfer a value from each ComboBox into a different property in my class.
Ex: I have 5 MyCB : ComboBox and MyClass with 5 properties. When I start my processing I need to take a value from each ComboBox and put it into a different Property.
MyClass.PropA = MyCBa.MyValue;
MyClass.PropB = MyCBb.MyValue;
MyClass.PropC = MyCBc.MyValue;
…ect…
This doesn’t “feel” like the best way to do this. I came to this feeling when I needed to do a similar process for 20 items and was just cutting and pasting code and changing a letter.
My question is: Is there a more OO way of doing this, or a “best practice” method/pattern for this type of mapping? I would love to hear all ideas and suggestions.
Thank you all for your time!
|
|
|
|
|
You could create a global static binder class that contains both set of properties (the ones for class A, and the ones for class B). In the Setter method for both sets of properties, just set the other set of properties with the specified value. Then, when you Get the property (no matter which version), you'll always get the same value for the given property.
I think that would be one way...
Of course, you could just derive class b from class a (a from b, whichever is applicable) and then you'd get to use all those properties without having to do anything special..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
|
|
|
|
|
Of course this is not the "preferred" MS way because it does not use data binding. Also, it does violate the principle of Data Hiding so it isn't the best OO method either but it is easy.
public class MySpecialLittleComboBox : ComboBox{
private MyClass MyClass{
get;
set;
}
protected override void OnSelectedIndexChanged(EventArgs e) {
base.OnSelectedIndexChanged(e);
MyClass.SomeProperty = (Items)SelectedItem;
}
public MySpecialLittleComboBox(List<Item> items, MyClass myClass){
Items.Clear();
foreach (Item item in items) {
Items.Add(item);
}
MyClass = myClass;
if(Items.Count > 0)
SelectedIndex = 0;
}
}
|
|
|
|
|
Hello,
i am using visual C# express 2008. I SOMETIMES get the illegal cross thread operation in my invoke method when i try to run my project. I check the InvokeRequired property, invoke the same method and in the 'else' condition i create atemporary variable and assign it the text of my control. But on that line, in the 'else' statement, inside the Invoking method i sometimes get the exception. What could be the cause? How to get rid of it? It does not occur often, but it is still a bug...
TY
|
|
|
|
|
Try using BeginInvoke on your control instead.Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
FYI, that would prevent a locking situation, but would not likely prevent a cross-thread exception. It would also change the flow of the program (i.e., the call would be asynchronous rather than blocking), which the OP may not want.
|
|
|
|
|
I agree.
|
|
|
|
|
Without seeing your code, it's pretty much impossible to tell you where it's going wrong.
|
|
|
|
|
Code is the following:
Delegate:
private delegate void ChangeTextDelegate(string text);
Method:
public static void ChangeText(string text)
{
if (richtextbox1.InvokeRequired)
{
richtextbox1.Invoke(new ChangeTextDelegate(ChangeText), new object[] { text });
}
else
{
int startIndex;
startIndex = richtextbox1.TextLength; <- Exception points here
...
}
}
I call it like this: ChangeText("hello"); (in another thread)modified on Thursday, March 18, 2010 7:19 AM
|
|
|
|
|
Hi,
please show code inside PRE tags, that results in better readability.
What you have shown seems correct, assuming the RTB got created on the GUI thread. It would be wrong when created e.g. inside the DoWork handler of a BackgroundWorker. How and where did you create it?
|
|
|
|
|
FYI, this is what code looks like when you wrap it in PRE tags and specify C# for the LANG attribute, as Luc mentioned:
private delegate void ChangeTextDelegate(string text);
public static void ChangeText(string text)
{
if (richtextbox1.InvokeRequired)
{
richtextbox1.Invoke(new ChangeTextDelegate(ChangeText), new object[] { text });
}
else
{
int startIndex;
startIndex = richtextbox1.TextLength;
}
}
Not sure why you are getting an exception there (perhaps post a screenshot and the full text of the exception?), but you might try the following to see if it works (changes in bold):
private delegate void ChangeTextDelegate(string text);
public static void ChangeText(string text)
{
if (<big><big>this</big></big>.InvokeRequired)
{
<big><big>this</big></big>.Invoke(new ChangeTextDelegate(ChangeText), new object[] { text });
}
else
{
int startIndex;
startIndex = richtextbox1.TextLength;
}
}
FYI, here is what I typed to make the code look like it does above:
<pre lang="C#">// Delegate:
private delegate void ChangeTextDelegate(string text);
// Method:
public static void ChangeText(string text)
{
if (<b><big><big><u>this</u></big></big></b>.InvokeRequired)
{
<b><big><big><u>this</u></big></big></b>.Invoke(new ChangeTextDelegate(ChangeText), new object[] { text });
}
else
{
int startIndex;
startIndex = richtextbox1.TextLength; // <- Exception points here.
// ...
}
}</pre>
|
|
|
|
|
Here is the stack trace, perhaps it can help clarify the problem...
System.InvalidOperationException was unhandled
Message="Cross-thread operation not valid: Control 'SomeClass' accessed from a thread other than the thread it was created on."
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.Control.get_InternalHandle()
at System.Windows.Forms.Control.WmWindowPosChanged(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
at System.Windows.Forms.RichTextBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WmCreate(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
at System.Windows.Forms.RichTextBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
at System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.TextBoxBase.CreateHandle()
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.RichTextBox.get_TextLength()
at SomeNamespace.SomeClass.Changetext(String text, Color color) in C:\...\SomeClass.cs:line 827
at SomeNamespace.SomeClass.SomeThreadFun() in C:\...\SomeClass.cs:line 112
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
|
|
|
|
|
Soo, any ideas?
|
|
|
|
|
I assume you already tried using the "this" keyword like I said above? If that doesn't work, you can take two approaches. With one approach, try to create the error with a very small tester form. Then, post that here for us to review. Or, try removing code from your project little by little until it starts working.
|
|
|
|
|
I am currently testing it with the 'this' keyword. But why should this approach solve the problem? What are the technicalities behind it?
|
|
|
|
|
Was just a wild guess really. Not sure if it would help.
|
|
|
|
|
Okay, that didn't help Any more ideas?
|
|
|
|
|
Show me the exact code that causes the problem. Create as small of a tester application as you can and paste ALL of the code for it (but remember to try and make the example concise). It's probably something simple, but I can't help you unless I see the code you are using.
|
|
|
|
|
I was finally able to fix the problem:
Apparently the handle for the richtextbox did not exist when i tried to invoke it. Since i used it in a background thread, the invokerequired property returned 'false', sometimes causing it to display the illegal cross thread operation exception (suring program startup).
The solution was to use the Form_load event which would signal the background thread when it was fully loaded.
But its still a bit unclear how such a thing can happen. When does actually InitializeComponent return? When can i be sure that the control handles exist?
|
|
|
|