|
I have sent you the code as a Zip attachment. Although the code is in VB.NET I think you won;t have any problems porting it to C#. I couldn't post the code here because the code's long...... really long.....
Happy Printing...
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
http://www.codeproject.com/csharp/letaonarticle2.asp
|
|
|
|
|
The code are looks like this:
Panel panel1 = new Panel();
if(panel1.CanFocus){
panel1.Focus();
}
Then it generated a exception at the run-time.
An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
Additional information: Collection was modified; enumeration operation may not execute.
Focus() has nothing to do with the collection, is that because of UIPermission fails?
Thanks
|
|
|
|
|
Perhaps a handle of panel1 fires a method that generates that exception or that prepare the field for the exception.
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
You're getting this error because a Panel control cannot receive the input focus. See Control.Focus()[^] for a list of controls that cannot be .Focus ed.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks a lot. I will try to not use focus() in my code.
In fact, my problem is as this:
if(A.Focused){
B.Focus();
A.Focus(); //get an exception in main()
}
The reason for reset A's focus is that I want to clear A's keyboard input buffer. Otherwise the A's keyboard input will always be put into the next selected item.
I guess it is a bug in .net library and it can not be fixed without the source code.
Thanks again.
Merry Christmas to everybody
|
|
|
|
|
This won't clear the keyboard buffer. Once the keystrokes are sent the that window, that's it. That window has to process them.
BTW: This is NOT a bug in the .NET Framework. This is the documented behavior of the control! The bug is in the design of your code.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi, someone knows what kind of component/widget/technique is needed to emulate the MSN (7.5) Options window behavior?
I mean, when you click any option in the listBox on the left, the groupBox of the right changes accordingly (with different set of options for each selected item).
I want to do a Configuration dialog like that and it seems not so obvious for me to figure out the best or smart way to do that.
Thanks in advance
Zopiro
|
|
|
|
|
How to break long line of code into several lines of short codes like what one can do in C++?
Thanks!
Devin
|
|
|
|
|
int my_very_long_variable_name = My_Very_Long_Method_Name(my_first_argument, my_second_argument, my_third_and_longest_argument, "some very long long string....");
Can be writen as well as
int my_very_long_variable_name = My_Very_Long_Method_Name(
my_first_argument,
my_second_argument,
my_third_and_longest_argument,
"some very long"+
" long string...."
);
btw, if you have a very long math expession, uualy is more useful to write it step by step (aoiding bugs is a must)
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
|
<br />
int i;<br />
Form2 f2=new Form2();<br />
<br />
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
f2.Show();<br />
f2.textBox1.Text=i.ToString();<br />
loop();<br />
}<br />
private void loop()<br />
{<br />
for(i=1; i<1000000;i++)<br />
{<br />
f2.textBox1.Text=i.ToString();<br />
f2.Refresh();<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
With above code, I want to let i show in the testbox1 of form2 while the interation in funcion loop in going on. When I run the program. at first it works, but after i get to around 10000, the form2 freezs,and it will not update the value of i. If I click the form. The form2 's text will show some thing like ( not responding).
How can I fix this problem?
Thank.
|
|
|
|
|
Threads would solve your problems. Create the second form on a separate thread (and paint it - set the text property to aother controls) and all things should run smoothly.
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
Thank you for your response.
I have never program in thread. can you please give me an example or a source online where i can find an example?
Thanks
|
|
|
|
|
Search on CodeProject an example of SplashScreen (they are kind o the same, use threads in order to display dinmicaly changing data)
Implementing with threads your solution may not be the best method, but from what I can imagine this may work fine. If you want me to help you more specify in what circumstances you show the second form, and how long (until a button is pressed, or until a time is elapsed)
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
Here's some code. No comments, though. I'm sick today and don't feel that loquacious. Hope it helps.
using System;
using System.Threading;
using System.Windows.Forms;
namespace Project1
{
public class MainForm : Form
{
private OtherForm otherForm;
public MainForm()
{
otherForm = new OtherForm();
Button b = new Button();
b.Text = "Click Me";
b.Click += new EventHandler( RunAThread );
Controls.Add( b );
}
private void RunAThread( object sender, EventArgs ea )
{
otherForm.Show();
ThreadWorker tw = new ThreadWorker( otherForm.tb, new OtherForm.UpdateText( otherForm.UpdateTextBoxText ) );
Thread t = new Thread( new ThreadStart( tw.RunAlotOfIterations ) );
t.IsBackground = true;
t.Start();
}
[STAThread]
public static void Main( string[] args )
{
Application.Run( new MainForm() );
}
}
public class OtherForm : Form
{
public TextBox tb;
public OtherForm()
{
tb = new TextBox();
tb.Dock = DockStyle.Fill;
Controls.Add( tb );
}
public delegate void UpdateText( string text );
public void UpdateTextBoxText( string text )
{
Controls[ 0 ].Text = text;
}
}
public class ThreadWorker
{
private Control c;
private OtherForm.UpdateText ut;
public ThreadWorker( Control target, OtherForm.UpdateText del )
{
c = target;
ut = del;
}
public void RunAlotOfIterations()
{
for( int i = 1; i < 1000000; i++ )
{
c.Invoke( ut, new object[] { i.ToString() } );
}
}
}
}
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
In this case, launching another thread is overkill. All you need to do is let your app process the WM_PAINT messages it's getting when you call .Refresh()
private void loop()
{
for(i=1; i<1000000;i++)
{
f2.textBox1.Text=i.ToString();
f2.Refresh();
Application.DoEvents();
}
}
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have a data grid that is displaying data from a MSAccess Database. Using a oleDbAdapter. Everything works well with the datagrid, add/update/insert/delete, are all good when I type directly into a cell. Howevere, when I choose a value from a combo box, outside the datagrid, and press a button that changes a selected cell in the datagrid, the update to the database does not occur. I know it has something to do with typing directly into the cell versus just setting the cell equal to a value.
//This line of code successfully puts the data in the grid
dataGrid1[gRowSelected,4] = cmbGenre.Text;
//But the update of the DB does not happen, A restart of the app shows the previous data
oleDbDataAdapter1.Update(myDataSet);
myDataSet.AcceptChanges();
dataGrid1.Update();
does anyone know how I can get the data I put into the grid to get into the Database? Do I need to refresh that dataset from the datagrid? Is that possible? Any clues????
Thanks
AuZi2005
|
|
|
|
|
I think that you should get the row you are trying to modify and do your stuff there (if you want the row selected in the grid use the grid's BindingManager, or if you know some field from the row use the DataTable's Select method, ...)
Hope this helps.
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
Thanks, the reference to the Grid's BindingManager was what I was looking for. Did not know how to use the grid to get back to the dataset. got it working, thanks
|
|
|
|
|
Hello,
I hope someone can help with this problem.
I'm working on an app which reads the company database for a range of scanned images according to user and date. It retrieves a list of all relevant scans and displays the results in a datagrid, date scanned, image location etc. The image is not displayed.
When I hit the Export button, the 'grid is made into an Excel spreadsheet and all the images downloaded locally. I need the image location column of the spreadsheet to be a relative hyperlink to the local copy of the images that were downloaded.
I can go into the spreadsheet and manually turn every link into a hyperlink which is OK when the result set is only a few lines but there could be hundreds of rows potentially. I want to be able to do it programatically. Any ideas?
I've messed about with the text in the spreadsheet as it is written with things like
xl.Cells[rowIndex + 1, 5] = "/images/" + filename.Substring(45, 10) + ".jpg";
trying to turn it into a relative link this way but no dice.
Any ideas please, as I'm stumped.
Thanks in advance and Merry Christmas to everyone
Scott
scotlandc
|
|
|
|
|
I need to have a menu with similar look and feel like the MainMenu except that I need to be able to put it anywhere in form( making little flexible). I started having Panel as holding main menu items. I need to provide functionality pretty much same as MainMenu. That means if a menu item has children it should be able to add an arrow to the right and show the sub menus on mouse over and make appropriate menus invisible on mouse out.
I would appreciate if anyone would throw some light into it.
Thanks in advance,
VPMahank
|
|
|
|
|
i need to create a table with this value for every row:
Text
Text
Hyperlink
Note
Text
i've to thounght about create an excel table in my form.
My question are:
1)How can i control the field so to create hyperlink, set value or delete?
2)I've serched on COM dll about excel but i've found nothing!
Where is the excel dll?
|
|
|
|
|
Check out the Microsoft PIA's.
|
|
|
|
|
Hi,
Could you please recommend one good book on .net 2.0 and sql server 2005 (win or web)
Thanks
|
|
|
|