|
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.
|
|
|
|
|
The autopostback did not work, as my textbox is in a template column in the datagrid, do I perform the following?
private void CheckBox1_CheckedChanged(object sender, System.EventArgs e)
{
DataGrid1.DataBind();
}
The checkbox is still showing as unchecked. Here is my complete code if this helps. Thanks!
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Collections.Specialized;
namespace DeleteMergeSegments
{
///
/// Summary description for WebForm1.
///
public class WebForm1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected DeleteMergeSegments.segmentDS segmentDS1;
protected System.Web.UI.WebControls.Button Delete;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
sqlDataAdapter1.Fill(segmentDS1);
DataGrid1.DataBind();
int loop1;
// Load NameValueCollection object.
NameValueCollection coll=Request.QueryString;
// Get names of all keys into a string array.
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
String[] arr2 = coll.GetValues(arr1[loop1]);
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.segmentDS1 = new DeleteMergeSegments.segmentDS();
((System.ComponentModel.ISupportInitialize)(this.segmentDS1)).BeginInit();
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
this.Delete.Click += new System.EventHandler(this.Delete_Click);
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "mergeSegment", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("iQuoteId", "iQuoteId"),
new System.Data.Common.DataColumnMapping("siLineNumber", "siLineNumber"),
new System.Data.Common.DataColumnMapping("chSegmentDesc", "chSegmentDesc"),
new System.Data.Common.DataColumnMapping("iMergeSegmentQty", "iMergeSegmentQty")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = @"DELETE FROM mergeSegment WHERE (iQuoteId = @Original_iQuoteId) AND (siLineNumber = @Original_siLineNumber) AND (chSegmentDesc = @Original_chSegmentDesc) AND (iMergeSegmentQty = @Original_iMergeSegmentQty OR @Original_iMergeSegmentQty IS NULL AND iMergeSegmentQty IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_iQuoteId", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "iQuoteId", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_siLineNumber", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "siLineNumber", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_chSegmentDesc", System.Data.SqlDbType.VarChar, 75, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "chSegmentDesc", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_iMergeSegmentQty", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "iMergeSegmentQty", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=QED_IT4;packet size=4096;user id=sa;password=157m0nd0;data source=" +
"Production1;persist security info=False;initial catalog=laaf_o";
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = @"INSERT INTO mergeSegment(iQuoteId, siLineNumber, chSegmentDesc, iMergeSegmentQty) VALUES (@iQuoteId, @siLineNumber, @chSegmentDesc, @iMergeSegmentQty); SELECT iQuoteId, siLineNumber, chSegmentDesc, iMergeSegmentQty FROM mergeSegment WHERE (iQuoteId = @iQuoteId) AND (siLineNumber = @siLineNumber)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@iQuoteId", System.Data.SqlDbType.Int, 4, "iQuoteId"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@siLineNumber", System.Data.SqlDbType.SmallInt, 2, "siLineNumber"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@chSegmentDesc", System.Data.SqlDbType.VarChar, 75, "chSegmentDesc"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@iMergeSegmentQty", System.Data.SqlDbType.Int, 4, "iMergeSegmentQty"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT iQuoteId, siLineNumber, chSegmentDesc, iMergeSegmentQty FROM mergeSegment " +
"WHERE (iQuoteId = 10153)";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE mergeSegment SET iQuoteId = @iQuoteId, siLineNumber = @siLineNumber, chSegmentDesc = @chSegmentDesc, iMergeSegmentQty = @iMergeSegmentQty WHERE (iQuoteId = @Original_iQuoteId) AND (siLineNumber = @Original_siLineNumber) AND (chSegmentDesc = @Original_chSegmentDesc) AND (iMergeSegmentQty = @Original_iMergeSegmentQty OR @Original_iMergeSegmentQty IS NULL AND iMergeSegmentQty IS NULL); SELECT iQuoteId, siLineNumber, chSegmentDesc, iMergeSegmentQty FROM mergeSegment WHERE (iQuoteId = @iQuoteId) AND (siLineNumber = @siLineNumber)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@iQuoteId", System.Data.SqlDbType.Int, 4, "iQuoteId"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@siLineNumber", System.Data.SqlDbType.SmallInt, 2, "siLineNumber"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@chSegmentDesc", System.Data.SqlDbType.VarChar, 75, "chSegmentDesc"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@iMergeSegmentQty", System.Data.SqlDbType.Int, 4, "iMergeSegmentQty"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_iQuoteId", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "iQuoteId", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_siLineNumber", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "siLineNumber", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_chSegmentDesc", System.Data.SqlDbType.VarChar, 75, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "chSegmentDesc", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_iMergeSegmentQty", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "iMergeSegmentQty", System.Data.DataRowVersion.Original, null));
//
// segmentDS1
//
this.segmentDS1.DataSetName = "segmentDS";
this.segmentDS1.Locale = new System.Globalization.CultureInfo("en-US");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.segmentDS1)).EndInit();
}
#endregion
private void Delete_Click(object sender, System.EventArgs e)
{
SqlConnection sc2 = new SqlConnection("workstation id=QED_IT4;packet size=4096;user id=sa;password=157m0nd0;data source=Production1;persist security info=False;initial catalog=laaf_l");
sc2.Open();
SqlCommand sCmd2 = sc2.CreateCommand();
SqlDataAdapter sda2 = new SqlDataAdapter();
sda2.DeleteCommand = sCmd2;
foreach(DataGridItem DataGridItem in DataGrid1.Items)
{
if(DataGridItem.Cells[0].Controls[0] is CheckBox)
{
CheckBox Checkbox1 = (CheckBox)DataGridItem.Cells[0].Controls[0];
if(Checkbox1.Checked == true)
{
sCmd2.CommandType=CommandType.Text;
sCmd2.CommandText = "del_merge_segment " + Request.QueryString.Get("iQuoteId") + "," + Request.QueryString.Get("txtLineNumber");
}
}
}
SqlCommand sCmd3=sc2.CreateCommand();
SqlDataAdapter sda3 = new SqlDataAdapter();
sda3.UpdateCommand = sCmd3;
sCmd3.CommandType = CommandType.Text;
sCmd3.CommandText ="resequence_merge_lines " + Request.QueryString.Get("iQuoteId");
}
AND HERE IS THE HTML:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="DeleteMergeSegments.WebForm1" %>
<title>WebForm1
<asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 72px" runat="server" width="880px" cellpadding="1" cellspacing="2" forecolor="Purple" backcolor="#D8D8E6" autogeneratecolumns="False" datamember="mergeSegment" datasource="<%# segmentDS1 %>" borderstyle="Solid" bordercolor="White">
<selecteditemstyle horizontalalign="Center" forecolor="Indigo" verticalalign="Middle" backcolor="#D8D8E6">
<edititemstyle horizontalalign="Center" forecolor="Indigo" verticalalign="Middle" backcolor="#D8D8E6">
<alternatingitemstyle horizontalalign="Center" forecolor="Indigo" verticalalign="Middle" backcolor="#D8D8E6">
<itemstyle horizontalalign="Center" forecolor="Indigo" verticalalign="Middle" backcolor="#D8D8E6">
<headerstyle horizontalalign="Center" forecolor="White" verticalalign="Middle" backcolor="DarkSlateBlue">
<columns>
<asp:templatecolumn sortexpression="siLineNumber" headertext="Delete">
<headerstyle horizontalalign="Center" forecolor="White" verticalalign="Middle" backcolor="DarkSlateBlue">
<itemstyle horizontalalign="Center" verticalalign="Middle" backcolor="#D8D8E6">
<itemtemplate>
<asp:checkbox id="CheckBox1" runat="server">
<asp:boundcolumn datafield="iQuoteId" sortexpression="iQuoteId" headertext="iQuoteId">
<headerstyle horizontalalign="Center" verticalalign="Middle">
<itemstyle horizontalalign="Center" verticalalign="Middle">
<asp:boundcolumn datafield="siLineNumber" sortexpression="siLineNumber" headertext="siLineNumber">
<headerstyle horizontalalign="Center" verticalalign="Middle">
<itemstyle horizontalalign="Center" verticalalign="Middle">
<asp:boundcolumn datafield="chSegmentDesc" sortexpression="chSegmentDesc" headertext="chSegmentDesc">
<headerstyle horizontalalign="Center" verticalalign="Middle">
<itemstyle horizontalalign="Center" verticalalign="Middle">
<asp:boundcolumn datafield="iMergeSegmentQty" sortexpression="iMergeSegmentQty" headertext="iMergeSegmentQty">
<headerstyle horizontalalign="Center" verticalalign="Middle">
<itemstyle horizontalalign="Center" verticalalign="Middle">
<asp:button id="Delete" style="Z-INDEX: 102; LEFT: 48px; POSITION: absolute; TOP: 32px" runat="server"
="" text="Delete"><asp:hyperlink id="HyperLink1" style="Z-INDEX: 103; LEFT: 832px; POSITION: absolute; TOP: 40px"
="" runat="server" navigateurl="ViewMergeSegments.asp">return
|
|
|
|
|
Hmm... well you're definately not getting the correct value of checked because it has to post back to the server in order for your code to see the right value. I'm not sure how to get it to post back in this instance, anybody else have any suggestions?
|
|
|
|
|
I am very carefull about declaring variables. But in a project i get out of memory exception, generally after close a form i use GC.Collect.
In this project , I connect a Sql Server with a sqlConnection declared as public in a module. Because in every task, i use this connection object. Before task i open that, when i achive the task, i close the connection. can This be cause?
|
|
|
|
|
It can be possible that the object is not disposing correctly, but that is pretty rare at least in my experience with c#. Can you possibly provide some code snippets from your form so we can get an idea of how this can be occuring?
-- modified at 13:12 Friday 7th October, 2005
|
|
|
|
|
I dispose each form at their closed event Like
Private Sub DisposeClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed<br />
Me.Dispose()<br />
GC.Collect() : GC.SuppressFinalize(Me)<br />
End Sub
But i think something is wrong , sometimes all menus on main forms cannot be painted then i get OUT Of Memory Exception..
How can i manage my memory?
|
|
|
|
|
When your UI elements go wacky like this it usually means you are abusing allocation. For instance you released a Menu handle even though its still supposed to be in use.
I would recommend going back to a "clean" codebase. The .Net Framework has managed memory for a reason and you should in almost every case let it do its own management. Without more details on why you need to agressively manage automatically managed resources I am not sure how we can help further.
|
|
|
|
|
just for safe keeping, I would let the GC handle itself. As far as I know it is not recommended to force a GC.Collect(). Also, I can see by the look of your code that you are using VB.NET and not C#, I would post this on the VB.NET forums and see if somebody over there can out out as well. Try letting the environment handle the form closes and disposes and GC collects. Just for grins, comment out all of your Me.Dispose() and GC.Collect(). and see if you still see the error.
|
|
|
|
|
How to i get the cursor position. I mean the x and y coordinates. I am desparate. Some one help. to be precise in a richtextbox control.
Nana
|
|
|
|
|
richTextBox1.GetPositionFromCharIndex(richTextBox1.SelectionStart)
|
|
|
|
|
I think he is wanting to get the position that the mouse is currently in. One way I can think to do it is to keep the current mouse position in memory using the MouseMove event. Set up a MouseMove event on the control and then use the event args that are passed to the delegate to store the mouse position in memory. Then, when you are wanting to retrieve the mouse position in another event (such as onClick) simply retrieve the positions you had already stored.
|
|
|
|
|
Am so sorry to border you but its not working. am so stressed right now. I even applied the PointToClient. Am just the getting the right points. Like where the current cursor is pointing. thx
Nana
|
|
|
|
|
the code below should work for you:
<br />
Point p = this.textBox1.PointToClient(Cursor.Position);<br />
int x = p.X;<br />
int y = p.Y;<br />
Except of course use your control instead of textBox1.
|
|
|
|
|