|
I've written a C# winform app and I'm new on C#...but I've some experience in programming...
I've some problems that I can't found anywhere a resolution...
My program is designed to have a main MDI form and a lot of MDI childs...so my questions are:
1)I create dinamically menu on MDI form and I've assigned to each of the a shortcut...but for the first element (i.e. "&File" menu than I've assigned Shortcut.CTRLF) it doesn't work...why?!?
the code is this:
void menuBuilder(object sender, System.EventArgs e)
{
MainMenu mainMenu = new MainMenu();
MenuItem file = new MenuItem();
file.MergeOrder=0;
file.MergeType=MenuMerge.MergeItems;
file.Text="&File";
file.Index=0;
file.Shortcut=Shortcut.CtrlF;
mainMenu.MenuItems.Add(file);
this.Menu=mainMenu;
}
2)I have a MDI child open correctly in my app from MDI menu (that I'll call FORM1) and I want that from FORM1, when it's loaded, to open another MDI child (FORM2) with a datagrid inside it.To do this I do this...
FORM2 newMDIChild = new FORM2();
newMDIChild.MdiParent = this.MdiParent;
newMDIChild.Show();
I suppose that in this manner I can load FORM 2 as a MDI child but it not seems to work, becouse if I tested if the window is open it doesnt works...and open another window!
2a)I try to close FORM2 when I close FORM1 but I can never do it...how can I do?!?I try everything but never works...
2b)When I do some works on FORM1, I write something on an ACCESS DB and then I'd like FORM 2(that is active too) update datagrid inside it...but I try everything but nothing work!!!I try to call a method on FORM2 from FORM1 becouse I suppose that it updates my datagrid...
The code is:
public void ReadResults()
{
OleDbDataAdapter da = new OleDbDataAdapter();
OleDbConnection con =new OleDbConnection();
OleDbCommand cmd = new OleDbCommand();
DataTable dt =new DataTable();
dt.Clear();
con.ConnectionString=<connstr>;
con.Open();
cmd.Connection = con;
cmd.CommandText = "SELECT * FROM TBL";
da.SelectCommand = cmd;
da.Fill(dt);
dataPreResult.SetDataBinding(dt,"");
cmd.Cancel();
con.Close();
}
I call this method on FORM2_Load and work fine...but if I want to reload datagrid when the FORM2 is displayed...what I've to do?!?
Help me please...I know that this are very stupid questions...but I didnt find anything everywhere that can help me...
|
|
|
|
|
You forgot to add click event & handler in your first block of code.
You can rewrite your code and add required functionality.
void menuBuilder(object sender, System.EventArgs e)<br />
{<br />
MainMenu mainMenu = new MainMenu();<br />
<br />
MenuItem file = new MenuItem();<br />
file.MergeOrder=0;<br />
file.MergeType=MenuMerge.MergeItems;<br />
file.Text="&File";<br />
file.Index=0;<br />
file.Shortcut=Shortcut.CtrlF;<br />
file.Click+=new EventHandler(file_Click);<br />
mainMenu.MenuItems.Add(file);<br />
<br />
this.Menu=mainMenu;<br />
}
private void file_Click(object sender, EventArgs e)<br />
{<br />
<br />
MessageBox.Show("Clicked");<br />
}
And i am sorry about your second queary. Because i can not figurout what you really want to achive.
Sreejith Nair
[ My Articles ]
|
|
|
|
|
But if File menu has submenus...what event I've to set for him?
something like this...
void menuBuilder(object sender, System.EventArgs e)
{
MainMenu mainMenu = new MainMenu();
MenuItem file = new MenuItem();
file.MergeOrder=0;
file.MergeType=MenuMerge.MergeItems;
file.Text="&File";
file.Index=0;
file.Shortcut=Shortcut.CtrlF;
file.Click+=new EventHandler(file_Click);
mainMenu.MenuItems.Add(file);
MenuItem campionato = new MenuItem();
campionato.MergeOrder=1;
campionato.MergeType=MenuMerge.MergeItems;
campionato.Text="&Campionato";
campionato.Click += new EventHandler(Championship_Open);
campionato.Shortcut=Shortcut.CtrlC;
campionato.ShowShortcut=true;
file.MenuItems.Add(campionato);
this.Menu=mainMenu;
}
private void file_Click(object sender, EventArgs e)
{
}
Will works or...not?
For second question...probably I'm confused...
In brief...I've a MDI application with this MDI childs(at the moment all MDI childs are closed):
1)MDIFORM (MDI container)
2)FORM1 (MDI form child)
3)FORM2 (MDI form child)
I press a menu on MDIFORM that opens FORM1.
In FORM1 there is a texbox and 1 button(btnOk).
On keyPress event of textbox I write in a MSAccess DB what I'm writing in a table.
Then I press a button and on click event I call this method btnOk_Click:
public class FORM1: System.Windows.Forms.Form
{
private void btnOk_Click(object sender, System.EventArgs e)
{
FORM2 newMDIChild = new FORM2();
newMDIChild.MdiParent = this.MdiParent;
newMDIChild.Show();
}
}
In FORM2 I've a datagrid where I show results written before in last MSAccess table.The code is this:
public class FORM2 : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
private System.Windows.Forms.DataGrid dataPreResult;
public FORM2()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.dataPreResult = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.dataPreResult)).BeginInit();
this.SuspendLayout();
//
// dataPreResult
//
this.dataPreResult.AllowSorting = false;
this.dataPreResult.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.dataPreResult.DataMember = "";
this.dataPreResult.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataPreResult.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.dataPreResult.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataPreResult.Location = new System.Drawing.Point(0, 0);
this.dataPreResult.Name = "dataPreResult";
this.dataPreResult.ReadOnly = true;
this.dataPreResult.RowHeaderWidth = 10;
this.dataPreResult.Size = new System.Drawing.Size(232, 613);
this.dataPreResult.TabIndex = 0;
//
// FORM2
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(232, 613);
this.Controls.Add(this.dataPreResult);
this.Location = new System.Drawing.Point(600, 10);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FORM2";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Load += new System.EventHandler(this.StringPreResult_Load);
((System.ComponentModel.ISupportInitialize)(this.dataPreResult)).EndInit();
this.ResumeLayout(false);
}
#endregion
public void StringPreResult_Load(object sender, System.EventArgs e)
{
ReadResults();
}
public void ReadResults()
{
OleDbDataAdapter da = new OleDbDataAdapter();
OleDbConnection con =new OleDbConnection();
OleDbCommand cmd = new OleDbCommand();
DataTable dt =new DataTable();
dt.Clear();
con.ConnectionString=<connectionstring>;
con.Open();
cmd.Connection = con;
cmd.CommandText = "SELECT * FROM TABLE";
da.SelectCommand = cmd;
da.Fill(dt);
dataPreResult.SetDataBinding(dt,"");
cmd.Cancel();
con.Close();
}
}
So now, my problems are:
1)When I push another time btnOk on FORM1 another FORM2 is showed.How can open one window?
2)if when I push MDIFORM menu's, when I open FORM1, I'll open FORM2 too, how can update datagrid in FORM2 from FORM1 when i write on FORM1 textbox?
Thanks for any ideas!
|
|
|
|
|
Instead of creating a new FORM2 everytime when the button is clicked, create a member variable of type FORM2 in FORM1, initializing it to null. In the event handler, test against null before creating the second form.
<br />
public class FORM1: System.Windows.Forms.Form<br />
{<br />
private FORM2 _secondForm = null;<br />
<br />
private void btnOk_Click(object sender, System.EventArgs e)<br />
{<br />
if (this._secondForm == null)<br />
{<br />
this._secondForm = new FORM2();<br />
this._secondForm.MdiParent = this.MdiParent;<br />
}<br />
<br />
this._secondForm.Show();<br />
}<br />
}<br />
This is just a simple fix, usually I try to have my mdi container manage my form instances.
In regards to your question regarding the second form accessing the first's textbox text, you could have the first form pass the second form a reference to itself. Again, this is much cleaner by having the MdiContainer manage interactions between child forms.
-cursor
|
|
|
|
|
Thanks for your answer...for the first question I try and it works great!
<b>And with the same method...I can close FORM2 from FORM1?</b>
For the second question, that's very important for me...could you give me an example how to solve this problem?I dont have so much experience with C# language to solve it...
Someone told me that for solve this problem I've to create a static method in FORM2 and then I can call it from FORM2 but I try but it there is an error...
the code is...
public class FORM2 : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
private System.Windows.Forms.DataGrid dataPreResult;
public FORM2()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.dataPreResult = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.dataPreResult)).BeginInit();
this.SuspendLayout();
//
// dataPreResult
//
this.dataPreResult.AllowSorting = false;
this.dataPreResult.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.dataPreResult.DataMember = "";
this.dataPreResult.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataPreResult.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.dataPreResult.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataPreResult.Location = new System.Drawing.Point(0, 0);
this.dataPreResult.Name = "dataPreResult";
this.dataPreResult.ReadOnly = true;
this.dataPreResult.RowHeaderWidth = 10;
this.dataPreResult.Size = new System.Drawing.Size(232, 613);
this.dataPreResult.TabIndex = 0;
//
// FORM2
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(232, 613);
this.Controls.Add(this.dataPreResult);
this.Location = new System.Drawing.Point(600, 10);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FORM2";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Load += new System.EventHandler(this.StringPreResult_Load);
((System.ComponentModel.ISupportInitialize)(this.dataPreResult)).EndInit();
this.ResumeLayout(false);
}
#endregion
public void StringPreResult_Load(object sender, System.EventArgs e)
{
ReadResults();
}
public static void ReadResults()
{
OleDbDataAdapter da = new OleDbDataAdapter();
OleDbConnection con =new OleDbConnection();
OleDbCommand cmd = new OleDbCommand();
DataTable dt =new DataTable();
dt.Clear();
con.ConnectionString=<connectionstring>;
con.Open();
cmd.Connection = con;
cmd.CommandText = "SELECT * FROM TABLE";
da.SelectCommand = cmd;
da.Fill(dt);
dataPreResult.SetDataBinding(dt,"");
cmd.Cancel();
con.Close();
}
}
I run code and this is the error:
<u><b>'FORM2.dataPreResult' denotes a 'field' where a 'class' was expected</b></u>
I'm so confused...what I've to do?
|
|
|
|
|
Nobody else can help me?
I dont know how to solve my problem...
|
|
|
|
|
Hi,
I’m currently writing a POS (Point Of Sale) system in c# with the database stored in sglexpress (using .Net 2).
Is there any kind of framework out there for this?
I would appreciate any tips, not just code but also UML and general ideas about it.
Thanks
Carl-Johan Larsson
|
|
|
|
|
hey,
would anyone plz tell me how the 'custom treeview' is created at runtime?
as in windows form...
if i have to create the same using remoting...plz do tell
|
|
|
|
|
What do you mean by "custom treeview", and at "runtime"? Certain things can be done at runtime, but most peoples definition of a "custom treeview" can only be done by creating a nerw TreeView class.
And what do you mean by doing this same thing using remoting? What are your trying to do?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi!
I would like to disable / remove tabs from the folder properties dialog of Windows Explorer. Optionally I would also like to add a custom tab.
This is definately possible as I have seen some programs do this, but how? Is this done by changing the registry or what?
Any ideas / help welcome!
Regards!
|
|
|
|
|
Another thing...
How do I know when a folder is being accessed by the user or application. I want to verify with biometric if user can access folder!
Regards!
|
|
|
|
|
Ligblou wrote:
How do I know when a folder is being accessed by the user or application.
You don't. The FileSystemWatcher class will tell you about modifications to the files, not when someone opens them.
Ligblou wrote:
I want to verify with biometric if user can access folder!
Absolutely redundent considering NTFS security already handles this for you, but not using biometric verification. You'd need to write a file system extension to handle this. Your code would have to handle cases where the file is being accessed by a machine with biometric hardware, without biometric hardware, and access from the network, both with and without biometric ahrdware. You'd also have to write utilities to manage the biometric authentication keys. Sound like fun!?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Sound like fun!?
It is! The full biometric system is in place. The folder security would be a nice add-on to the package. If I can get this working, I would also have a nice add-on for my multiple layer document encryption package using a HASP (hardware dongle). Loving modularity!!
I also thought about writing a File System Filter Driver (http://www.microsoft.com/whdc/driver/filterdrv/default.mspx[^]) to achieve this. It does seem like the best solution by far. Now, that sounds like fun!
Regards!
|
|
|
|
|
Ligblou wrote:
I would like to disable / remove tabs from the folder properties dialog of Windows Explorer
Depends on the tab your trying to turn off. This is done through group policies, not code. Click Start, pick Run, then type GPEDIT.MSC for the group policy editor.
Ligblou wrote:
Optionally I would also like to add a custom tab.
Never had to do this. But, it would problably be a Shell Extension (Google for this), and would require registry modifications to get the shell to know your extension is there.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thank your for the information about a Shell Extension - I will look into it.
Regards!
|
|
|
|
|
Hi every body
I wrote an application in Persian language that contains a text editor with RichTextBox.But when I click somewhere on untyped rich textbox area the system language switch between FA(Farsi) to EN ! How can I avoid this behavior or rich text box
|
|
|
|
|
hi, i am trying to read from a text (csv) file and update depending on the changes througth the ui, update certain fields back into the same text (csv) file
i cant find the right tool, or even if it is possible within C#
|
|
|
|
|
I would do it the following way:
1. Read line
2. Split line along the seperators and store it in memory (e.g. store an object containing the values of each line into an arraylist or hashtable)
At this point you have easy access to the information in the file. Depending on file-size, you might want to load "blocks" of information rather than the whole file. Simply display all the info you have and if the user "scrolls" close to the block-end, load the next block.
3. Change the values in memory as needed
4. Using the same seperator, write the file back (linewise).
(If you used blocks, you might have to use a temp-file)
At the lowest level it IS possible to overwrite a few bytes of a file. Usually its not worth the hassle, though, and if you mess up, you might be in trouble.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
I HAve written a chat applicaion on lan.but it chat on single window.
i want to show a new window on each user communication like yahoo or msn messanger.can anybody give me source code for this.or give idea for this.
|
|
|
|
|
Hi.
I have to create some kind of event tracker class, which should register hooking handlers to events. I need a method
RegisterEvent (object target, Delegate handler)
in which I add handler to event (target). Target is probalby System.MulticastDelegate. Is it possible to do that, even when I don't know the event name? I want to avoid changing this method to
RegisterEvent(object target, Delegate handler, string eventName).
All examples that I've found use GetEvent(name) from reflection, and than EventInfo.AddHandler(..)
Pszat
|
|
|
|
|
Hi!
You can use Type.GetEvents() to retrieve all events a type defines, regardless of event names.
The resulting EventInfo[] holds information on the event handler delegate signature, so you can continue from there.
Regards,
mav
|
|
|
|
|
Hi. I’m unfourtunately in this case from Sweden which have the letters å, ä, ö. When I read lines in a textfile using StreamReader I got a “?” symbol when I print these letters. Any idea what to do…
_____________________________
...and justice for all
APe
|
|
|
|
|
You'll have to give the encoding of the file when constructing the StreamReader.
Regards,
mav
|
|
|
|
|
Any Idea of which Encoding I should use. I've tried the regular once.
_____________________________
...and justice for all
APe
|
|
|
|
|
Depends on the encoding that was used to create the file.
You can try Encoding.Default for a start (which is _not_ the same as not specifying an encoding, strangely enough).
Regards,
mav
|
|
|
|