|
I know the formula, and indeed it's pretty simple. However, how can you use a loop or two, if you don't know how many times you will be calculating the IRR. Meaning, the first value of IRR is just a guess, and then the function will go through an array of values, to calculate the specific sum, and if the sum is not equal zero, then it picks another IRR rate value (based on a certain rule), and does the same sum operation. Therefore, it's not a loop or 2.
|
|
|
|
|
Hi there!
I hope you guys can help me, here's my problem:
I have a form (Form1) with a button (Button1) which open another form (Form2) as such:
<br />
Form2 frm2 = new Form2()<br />
<br />
frm2.Show();<br />
On the second form (Form2) I have a DataGridView with this code:
<br />
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)<br />
{<br />
this.Close();<br />
}<br />
My goal is to close the second form when the user double-clicks (makes a selection) in the DataGridView. I've tried more than 20 events and I always have the same problem:
Object reference not set to an instance of an object.
at System.Windows.Forms.DataGridView.HitTest(Int32 x, Int32 y)
Can you guys help me? Thanks!
|
|
|
|
|
I tried this with a DataGrid control and had no problems... where are you getting this DataGridView control?
|
|
|
|
|
Ahhhh, of course, sorry!
I'm using Visual Studio 2005 Beta 2... It's a grid that comes with .NET 2.0. It's VERY useful, much better than the old DataGrid IMHO.
|
|
|
|
|
Ahh I see... I have 2005 Beta 2 but am not willing to install it in my work environment. Until I get build a test env, I cannot provide any good help to ya.
Try these two methods though.
1.) Create a timer set to 100ms and have the timer_elasped event close the form. and start the timer inside your douleclick method. This would allow the method to complete and then run the close time. This is not a good way to do it, but probably the easiest.
2.) Create an event delegate to close the form. Inside the code for the control_click call the method this.Invoke(new delegatename(delegatemethod)); Then in the delegatemethod() call this.close; This is the thread safe way to run form methods on a click. Hit me back if you need realcode examples and I'll make some for ya
|
|
|
|
|
The timer would probably work but as you said, it's not a very good way of doing it.
The delegate doesn't work AFAIK, I receive this error:
Exception has been thrown by the target of an invocation.
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
The invoke calls the delegated method ASAP (before the HitTest did it's job I guess) and the same error (more or less) happens... I think I'll solve the problem in another way (adding a button comes to mind).
Thanks again for your help
|
|
|
|
|
My mistake, I should've used BeginInvoke instead of Invoke.
This line of code works perfect:
this.BeginInvoke(new MethodInvoker(this.Close));
Thanks again for your help!
|
|
|
|
|
I have an app with two dialogs, one opened by the second. With 2 monitors the 2nd dialog opens on the same monitor if I set it to open in a normal state. IF i have it set to open maximized it always opens on monitor1, regardless of which monitor the first is on. Is there a way to change this behavior.
|
|
|
|
|
You could possibly programatically set the dialog to open in coords of the second monitor first and then change the property to Maximized once the dialog has fully loaded.
|
|
|
|
|
I tried doing a programmatic maximize in the constructor, it didn't work. The form still opened maximized on monitor1. When I demaximized it the normal version was on monitor two, and manually maxing it left it on mon2 just like before.
|
|
|
|
|
You don't want to do it in the constructor because you don't want it to maximize until it has been fully created and painted.
|
|
|
|
|
Where should I move the call to then?
|
|
|
|
|
Try it in the form_load event. I'll toy with it a bit as well as I have dual monitors also.
|
|
|
|
|
Yes, this worked for me: (My second monitor is on the LEFT of the screen... if yours is on the right, you would have to move it to a coord PAST the first monitor)
<code>
private void Form2_Load(object sender, System.EventArgs e)
{
this.Left = -458;
this.WindowState = FormWindowState.Maximized;
}
</code>
|
|
|
|
|
I've got a tabcontrol with a number of databound textboxes on a tabpage
(Form1). I've got a button that the user clicks that opens a dialog (Form2)
and does a lookup from a database. The user makes a selection and chooses a
button wired dialog.ok to close the dialog (form2) and populate the fields on the tabcontrol (Form1). It all works except the textboxes don't retain the new data when I tab across to another tab page.
Code To Open Dialog (Form1)=========================
private void btnLmoLookup_Click(object sender, System.EventArgs e)
{
Form2 LmoLookup = new Form2();
LmoLookup.StartPosition = FormStartPosition.CenterParent;
if( LmoLookup.ShowDialog() == DialogResult.OK )
{
txtBoxDocName.Text = LmoLookup.docFullName;
}
LmoLookup.Dispose();
}
Code To Create Public Variable (Form2)======================
public string docFullName
{
get{return
this.dsExtPhysLookup1.Tables["tblExternalPhysicians"].Rows[this.listBox1.SelectedIndex]["docFullName"].ToString();}
}
|
|
|
|
|
What is a quick way to cast a string (consisting of a number) into an int variable? Isn't there some quick function build in somewhere?
|
|
|
|
|
Convert.ToInt32(string);
also Convert.ToInt16(string);
I would look at all of the methods that the Convert class provides, they will all come in handy
|
|
|
|
|
|
i think this should help
string s="3";
int i = Convert.ToInt32(s);
Leejo
|
|
|
|
|
I have a datagird and a checkbox web control within the datagrid, I am trying to step through each datagriditem and detect whether the checkbox is checked or not, however when testing this application, the checkbox always shows unchecked? I have bound the checked property to a column in the datagrid, and added a button shich will execute code to delete all lines whose checkbox is checked. Please Help!
|
|
|
|
|
Can you post a code snippet of how you are acquiring this task? It seems to me that once you store the object (CheckBox) in the datagrid all you need to do is simply pull the object back out and read/change its properties.
<code>
foreach(DataGridItem item in DataGrid.Items)
{
if(item is CheckBox)
{
CheckBox cb = (CheckBox)item;
cb.Checked = true;
}
}
</code>
-- modified at 13:15 Friday 7th October, 2005
|
|
|
|
|
This is what I have currently and is not working:
foreach(DataGridItem DataGridItem in DataGrid1.Items)
{
CheckBox Checkbox1 = (CheckBox)DataGridItem.Cells[0].Controls[1];
if(Checkbox1.Checked == true)
{
sCmd2.CommandType=CommandType.Text;
sCmd2.CommandText = "del_merge_segment " + Request.QueryString.Get("iQuoteId") + "," + Request.QueryString.Get("txtLineNumber");
}
|
|
|
|
|
I would be careful casting to a checkbox when not first check to make sure it is a checkbox you're looking for. Since you're using DataGridItem.Cells[0].Controls[1] I'm assuming that the checkbox is the second control in the datagriditem. What is the first control? Also, are you saying that Checkbox1.Check is always coming back true? One other thing: Is this a WinForm or a WebForm?
|
|
|
|
|
The checkbox is th only control in the datset, I changed .Controls[1] to [0]. This is a webform and when the page runs if a check a checkbox and step through my code the checked property of the box I checked is showing false which is why my delete command is never running. When I run the code now after making the above changes and check a box and then click delete I get an invalid cast exception for the following line of code:
CheckBox Checkbox1 = (CheckBox)DataGridItem.Cells[0].Controls[0];
Is their a better way to do this?
|
|
|
|
|
That is a good way to do it, but be sure to check for the checkbox first. Also, since this is a web form, you have to make sure the control posts back to the form. Set the checkbox's property (AutoPostBack = true).
Here is how you check to make sure it is a checkbox BEFORE you cast it so as not to receive any cast errors:
<br />
if(DataGridItem.Cells[0].Controls[0] is CheckBox)<br />
{<br />
CheckBox Checkbox1 = (CheckBox)DataGridItem.Cells[0].Controls[0];<br />
}<br />
This will make sure that you don't get an invalid cast exception. You may also have to bind the data to the datagrid on Check_Changed event of the checkbox after it posts back. I would try the autopost back first, then if that doesn't work use a DataGrid1.Databind() inside the CheckChenged event of the checkbox.
|
|
|
|