|
That is because the property frmFindReplace is null. Are you setting that property somewhere?
How are you opening the FindReplace form? You will need to keep that instance of the form in the Form1 to access the correct value of the property findme in the form1.
|
|
|
|
|
how do i store the property ?
and i am opening the form as follows :
private void findAndReplaceToolStripMenuItem_Click(object sender, EventArgs e)
{
frmFindReplace find = new frmFindReplace();
find.Clicked += new ButtonClick(find_Clicked);
find.ShowDialog();
}
|
|
|
|
|
There's a few things that you haven't shown that could be the problem but rather than guess at that I would suggest an easier way. Why not just raise an event and pass the text in the arguments back to the main form? Something like...
using System;
public class TextEventArgs : EventArgs
{
private string text;
public TextEventArgs(string text)
{
this.text = text;
}
public string Text
{
get { return text; }
}
}
using System;
using System.Windows.Forms;
public partial class FormFindAndReplace : Form
{
public event EventHandler<TextEventArgs> FindClicked;
public FormFindAndReplace()
{
InitializeComponent();
}
private void buttonFind_Click(object sender, EventArgs e)
{
OnFindClicked(new TextEventArgs(textBox.Text));
}
protected virtual void OnFindClicked(TextEventArgs e)
{
EventHandler<TextEventArgs> eh = FindClicked;
if (eh != null)
eh(this, e);
}
}
using System;
using System.Windows.Forms;
public partial class FormMain : Form
{
private FormFindAndReplace formFindAndReplace = null;
public FormMain()
{
InitializeComponent();
}
private void findAndReplaceToolStripMenuItem_Click(object sender, EventArgs e)
{
if (formFindAndReplace == null)
formFindAndReplace = new FormFindAndReplace();
formFindAndReplace.FindClicked += formFindAndReplace_FindClicked;
formFindAndReplace.FormClosing += formFindAndReplace_FormClosing;
formFindAndReplace.Show();
}
private void formFindAndReplace_FindClicked(object sender, TextEventArgs e)
{
Console.WriteLine(e.Text);
}
private void formFindAndReplace_FormClosing(object sender, FormClosingEventArgs e)
{
formFindAndReplace.FormClosing -= formFindAndReplace_FormClosing;
formFindAndReplace.FindClicked -= formFindAndReplace_FindClicked;
formFindAndReplace = null;
}
}
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Hi,
I am new to the singleton pattern. I read that it could be used to load all your website setting and configuration values. I also read that people avoid singletons, and people that do unit testing don't use singleton patterns. Why is this? Are singletons good to use in my scenario? If not, how should I do it then? And how can this be unit tested?
Thanks
Brendan
|
|
|
|
|
First since this is a web related question you should have used the ASP.NET or Web Development forums.
The singleton pattern is a tool like any other, it has its uses under the proper conditions to solve the proper problem. Since the web.config file contains the settings and configuration information for an ASP.NET app you are gaining nothing by trying to use a singleton. On the other hand if some settings are coming from a database, or other source, then a singleton instantiated by the application may be of use.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi,
My apologies for posting it here, but using it to get settings values was just an example. It was posted here because I had some questions regarding the design of the pattern. The main issue that I have is that there is some difficulty in unit testing it. How does one go about unit testing a singleton pattern, and testing all the methods in the .Instance property? Lets say I have something like:
BlogSettings.Instance.Name
How would I unit test .Name?
|
|
|
|
|
Use the Google [^]Pattern
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
The Singleton pattern is more for C++ and is not of much use in C#, especially since the introduction of static classes.
As for unit testing, I hear that they can make using mock objects difficult, but I'm not the one to ask about that.
|
|
|
|
|
PIEBALDconsult wrote: The Singleton pattern is more for C++ and is not of much use in C#
Got a source for that assertion?
|
|
|
|
|
That's my own conclusion.
|
|
|
|
|
I always use the singletom to save the system setting.
Because I never do the unit testing, I do not know why some people avoid singletons, perhaps there is better way than this.
|
|
|
|
|
How can i get MouseEventArgs in datagridview1_CellValidating cause i wanna to use this code in datagridview1_CellValidating:
if (dgvFactorSell.HitTest(e.X, e.Y).ColumnIndex <= dgvFactorSell.CurrentCell.ColumnIndex && dgvFactorSell.HitTest(e.X, e.Y).RowIndex == dgvFactorSell.CurrentRow.Index)
FlagIsBack = true;
private void dgvFactorSell_MouseClick(object sender, MouseEventArgs e)
{
if (dgvFactorSell.HitTest(e.X, e.Y).ColumnIndex <= dgvFactorSell.CurrentCell.ColumnIndex && dgvFactorSell.HitTest(e.X, e.Y).RowIndex == dgvFactorSell.CurrentRow.Index)
FlagIsBack = true;
}
modified on Sunday, June 20, 2010 1:47 PM
|
|
|
|
|
Well I am Noob at english language , I can talk , but I can't understand every thing ,
Excuse me , please! ,
Hope this code Help ...
private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
try
{
if (e.Button == MouseButtons.Right)
{
DataGridView.HitTestInfo hit = dataGridView1.HitTest(e.X, e.Y);
dataGridView1.CurrentCell = dataGridView1[0, hit.RowIndex];
}
}
catch
{
}
}
----- Please , Increase the Hit by 1 -----
www.smart-arab.com
I know nothing , I know nothing ...
|
|
|
|
|
|
I have not messagebox result and I really want to use it.
when I type it , it dosen't apear. I search and I find this
public enum messageboxresult
but I didn't khnow how to use it.
|
|
|
|
|
Here is an example of how to get the result from a message box.
private void doSomething()
{
DialogResult theResult = MessageBox.Show("Is this working?", "Well.......",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if (theResult == DialogResult.Yes)
{
}
}
|
|
|
|
|
In yes or no, this can be use
if (MessageBox.Show("Is this working?", "Well.......", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
}
else
{
}
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
MessageBoxButton buttons = MessageBoxButton.OKCancel;
MessageBoxImage icon = MessageBoxImage.Information;
MessageBoxResult defaultResult = MessageBoxResult.OK;
MessageBoxResult result = MessageBox.Show(message, caption, buttons, icon, defaultResult);
This is however available only in .Net framework 3 and above.
See here.
Quidquid latine dictum sit, altum videtur.
Whatever is said in Latin sounds profound.
|
|
|
|
|
if (DialogResult.Yes == MessageBox.Show("test", "ask", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
{
}
|
|
|
|
|
http://infynet.wordpress.com/2010/08/28/check-message-box-result
hi check this link.
|
|
|
|
|
http://infynet.wordpress.com/2010/08/28/check-message-box-result
hi check this link
|
|
|
|
|
I have a cell (cellIndex:5 and its in edit mode) that user must enter data in it then can go forword to next cell but if user didnt enter any data can only step back(I mean that user can go to all the cells before this Cell, for this example user can go to indexNumbers<5)and if the user didnt enter data must prevent from going to next cell and even next Row.
So please Help out !
|
|
|
|
|
Keep the columns ahead of current one disabled i.e. if user can enter data in column 5 only after entering some data in column 4, keep column 5 disabled initially. Have CellValidating event handler for the DataGridView. In that check for the value in the current cell. If user has entered value in it, enable the columns where user can edit/enter data.
|
|
|
|
|
Thanks for reply
But i want that user be able to go backword even if didnt entered any data in column 5.
|
|
|
|
|
You need something like this in the CellValidating event:
DataGridView dataGridView = sender as DataGridView;
dataGridView.Columns[5].ReadOnly = (e.ColumnIndex == 4 && string.IsNullOrEmpty(e.FormattedValue.ToString()));
User can move to any cell but the editing will be enabled only when the data is entered in the fourth cell.
|
|
|
|