|
create button1
and put it in button1_Click(....)
|
|
|
|
|
i used that codes in the button that i use it to open Form2
but still i didnt get the result i wished...and i used the same codes in the button tht i have Form2 that i use it to close Form2 but it didnt work also
|
|
|
|
|
try this:
in form1:
form2 f2=new form2();
f2.showdialog();
frm1_load(...);<<<<<<<<<<<<<<<<<<<<
|
|
|
|
|
Not a good idea - it ties the design of form1 to the design of form2. I.e. if you replace the datagrid view in form1 with some other construct then it needs changes to form2 as well. This defeats one of the aims of an OOP language.
A better approach is to create an event in form2 which you subscribe to in form1. Then form2 internally needs to know nothing about who is using the data, it just signals "my data has changed" and all forms that subscribe to the event then update themselves appropriately.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Hello,
for solving you're problem, you can use delegates.
Take a look here.
Cheer's,
Alex Manolescu.
|
|
|
|
|
so how i can use delegates here ??
i mean which parameter i can send to the method ??
i will be happy if u help me about it ?
|
|
|
|
|
hi,
I've made a small project for you.
Supose you have a DataGridView control with 1 column.
The value we need to pass to the AddRow method is the string info.
Form1:
- contains: a DataGridView and a Button
public partial class Form1 : Form
{
public delegate void InsertIntoDGV(string info);
public static InsertIntoDGV idv;
public Form1()
{
InitializeComponent();
idv = new InsertIntoDGV(AddRow);
}
public void AddRow(string info)
{
dataGridView1.Rows.Add(new object[] { info });
}
private void button1_Click(object sender, EventArgs e)
{
new Form2().ShowDialog();
}
}
And now Form2:
- contains a TextBox and a Button.
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form1.idv(textBox1.Text);
}
}
Hope this helps!
Cheer's,
Alex Manolescu.
|
|
|
|
|
Did it solved you're problem man?
At least answer if you post a problem!
|
|
|
|
|
Dear Expert I have usercontrol to create a new record/edit an existing record. The usercontrol have two constructors. one for "Create new record " and other for Load existing record for edit. When page have id in query string then load existing record for edit constructor execute otherwise create new rocord constructor executes.
The following is the code behind of usercontrol ("ContractControl")
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace DynamicForms.Portal.Controls
{
public partial class ContractControl : System.Web.UI.UserControl, IContract
{
protected bool _createMode;
public ContractControl()
{
_createMode = true;
this.Save += new EventHandler(ContractControl_Save);
this.Cancel += new EventHandler(ContractControl_Cancel);
}
public ContractControl(IContract contract)
{
_createMode = false;
this.Save += new EventHandler(ContractControl_Save);
this.Cancel += new EventHandler(ContractControl_Cancel);
ID = contract.ID;
Client_ID = contract.Client_ID;
Name = contract.Name;
}
protected void Page_Load(object sender, EventArgs e)
{
}
#region IContract Members
public Guid ID
{
get
{
return Guid.NewGuid();
}
set
{
ID = value;
}
}
public string Name
{
get
{
return NameTextBox.Text;
}
set
{
try
{
NameTextBox.Text = value;
}
catch
{
}
}
}
#region Public Events
public event EventHandler Save;
public event EventHandler Cancel;
#endregion
#region Default Public Event handelrs
protected void ContractControl_Save(object sender, EventArgs e)
{
//Do Nothing
}
protected void ContractControl_Cancel(object sender, EventArgs e)
{
//Do Nothing
}
#endregion
protected void SaveButton_Click(object sender, EventArgs e)
{
Save(this, e);
}
protected void CancelButton_Click(object sender, EventArgs e)
{
Cancel(this, e);
}
}
Following code execute on pageload of my webpage where I used above usercontrol
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.Params["id"] != null && Request.Params["id"].Length > 0)
{
Controllers.ContractController _controller=new Controllers.ContractController();
Controls.IContract _contract= _controller.Load(new Guid(Request["id"].ToString()));
ContractControl1 = new Controls.ContractControl(_contract);
}
else
{
ContractControl1 = new DynamicForms.Portal.Controls.ContractControl();
}
}
}
The new record is being created successfully. But editing throws following error
"An unhandled exception of type 'System.StackOverflowException' occurred in MyProject.web.DLL"
I am waiting your suggestions please.
|
|
|
|
|
Hi,
a StackOverflowException is always a hint that you produced an endless loop. I'm not able to see the problem in the code you posted, so I suggest you try to debug step-by-step.
Regards
Sebastian
|
|
|
|
|
UserControl is also inherited from IContract that I have passing to its constructor. Is this is making problem?
|
|
|
|
|
Maybe. Did you took look at the stack trace. Maybe the detail of the exception shows you where the problem is.
|
|
|
|
|
I have seen a database file that if you Attach it your self in SQL Server then the project that use that DB file will never runs anymore .
Alert :
If you attach that DB in Sql you can see all Tables , Views ,...
i am looking for that if someone attach my DB in SQL , my project never run on that system.
Alert :
I my self in project attach it.
modified on Monday, January 4, 2010 4:15 AM
|
|
|
|
|
Hallucinations? What is the question here? The hundreds of ways to make your database based application to not work. What are you actually looking for?
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
i am looking for that if someone attach my DB in SQL , my project never run on that system.
Alert :
I my self in project attach it.
|
|
|
|
|
jojoba2010 wrote: someone attach my DB in SQL
What do you mean by this? Can you try and explain a bit.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Q1:
How can i lock my database in sql server that nobody can attach or see the tables in that DB?
Q2:
I wanna to do something that if anybody attach my DB in SQL then the project (in C# ) never run and give Database Error.
|
|
|
|
|
You can do all this by setting permissions on your database in the SQL server and creating proper login credentials for the database.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Thanks for your ans and help
would you explain the process Step by Step so I can do that ?
|
|
|
|
|
This[^] should be a good start.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Thanks
i have done that but no diffrence ?
|
|
|
|
|
Now you can access the database using created user id and password. Just make sure you do not give that away. That way no one can access your database.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
I knew that but i want something that if anyone attach my DB then the program never runs.
Alert :
the DB can be attached as easy as creating DB.
|
|
|
|
|
You just keep repeating the question without really clarifying anything.
I think you trying to ask too much. To attach a database the user needs SQL admin privileges which would imply a level of knowledge and understand of why they were attaching the database, so what is the point of stopping the application from running?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi to everyOne
I have seen a program that create files and folders (in desire Root )that cant be access in Explorer or from MyComputer (just that files and folders are accessable in that program... that folder contains Images and word files , ...)
Alert : The file and folders are not hidden . cause i enabled Show hidden files and folder option .
|
|
|
|