|
|
 |
| ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

October 17th, 2009, 07:10 AM
|
|
Friend of Wrox
|
|
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sending values from Popup to Parent window
Hi All !!
It seems everyone in this forum works on Web Applications and I haven't found anyone helping out with Windows Applications . That's a pity.
I am working on a Windows Application where I have a Parent Windows Form which opens a Popup Window with a button click. In the Popup window there is a Listbox where I can choose a value & click OK.
With the OK button click event I have written code which picks up values from database depending on the value selected from the Listbox. Now after closing the Popup window with the OK button the values picked from the databases have to populate the Texbox controls of the Parent Windows Form
The code I have written works but with a Hitch. Every time I close the Popup window a new Parent Window is opened with the Textbox Controls populated and the original Parent Window remains open without any controls populated.
I am putting the codes from both the forms here. Kindly let know where I might have gone wrong. Remember there is no problem in retrieving values from Popup.
Code for Parent Window :
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Web;
namespace QuizPro
{
public partial class frmQuizName : Form
{
public frmQuizName()
{
InitializeComponent();
}
public frmQuizName(string strQid, string strQName)
{
InitializeComponent();
this.txbQuizid.Text = strQid;
this.txtQuizName.Text = strQName;
}
private void frmQuizName_Load(object sender, EventArgs e)
{
btnDelete.Visible = false;
}
private void btnSaveEdit_Click(object sender, EventArgs e)
{
if (txbQuizid.Text == "")
{
btnSaveEdit.Text = "&Save";
InsertRecords();
Refresh();
}
else
{
btnSaveEdit.Text = "&Edit";
EditRecords();
}
}
private void InsertRecords()
{
try
{
string newDt = Convert.ToString(DateTime.Now.Day) +"/" + Convert.ToString(DateTime.Now.Month) + "/" + Convert.ToString(DateTime.Now.Year);
OleDbConnection conn = TheConnection();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
string qid = getQuizID();
cmd.CommandText = "Insert into Quiz_Master(QuizID,Quiz_Name,CreatDt) values('" + qid + "','" + txtQuizName.Text + "','" + newDt + "')";
int recCount = cmd.ExecuteNonQuery();
MessageBox.Show("Record Inserted Successfully");
conn.Close();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
private void EditRecords()
{
}
private string getQuizID()
{
string QuzId = string.Empty;
OleDbConnection newcon = TheConnection();
OleDbCommand newcmd = new OleDbCommand();
newcmd.Connection = newcon;
OleDbDataAdapter dadpter = new OleDbDataAdapter("Select Count(*) as RecCount from Quiz_Master",newcon);
DataSet ds = new DataSet();
dadpter.Fill(ds, "Quiz_Master");
DataTable dt = ds.Tables[0];
if (dt.Rows[0]["RecCount"].ToString() != string.Empty)
{
if (dt.Rows[0]["RecCount"].ToString().Length == 1)
{
QuzId = "Q" + "000" + Convert.ToString(Convert.ToInt32(Convert.ToInt32(Convert.ToString(dt.Rows[0]["RecCount"])) + 1));
}
else if (dt.Rows[0]["RecCount"].ToString().Length == 2)
{
QuzId = "Q" + "00" + Convert.ToString(Convert.ToInt32(Convert.ToInt32(Convert.ToString(dt.Rows[0]["RecCount"])) + 1));
}
else if (dt.Rows[0]["RecCount"].ToString().Length == 3)
{
QuzId = "Q" + "0" + Convert.ToString(Convert.ToInt32(Convert.ToInt32(Convert.ToString(dt.Rows[0]["RecCount"])) + 1));
}
else if (dt.Rows[0]["RecCount"].ToString().Length == 4)
{
QuzId = "Q" + Convert.ToString(Convert.ToInt32(Convert.ToInt32(Convert.ToString(dt.Rows[0]["RecCount"])) + 1));
}
}
else
{
QuzId = "Q" + "0001";
}
return QuzId;
}
private void btnCancel_Click(object sender, EventArgs e)
{
Close();
}
private void btnShowQuiz_Click(object sender, EventArgs e)
{
ShowQuiz frmchild = new ShowQuiz();
frmchild.Width = 480;
frmchild.Height = 290;
frmchild.Top = 65;
frmchild.Left = 350;
frmchild.Show();
}
private OleDbConnection TheConnection()
{
OleDbConnection conn = new OleDbConnection();
string Connstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Quiz Software\\QuizDB.mdb";
conn.ConnectionString = Connstring;
conn.Open();
return conn;
}
}
}
Highlighted code shows the relevant code area.
Popup page Code:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace QuizPro
{
public partial class ShowQuiz : Form
{
public ShowQuiz()
{
InitializeComponent();
}
private void ShowQuiz_Load(object sender, EventArgs e)
{
try
{
DateTime newDt = DateTime.Now;
OleDbConnection newcon = TheConnection();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = newcon;
cmd.CommandText = "Select QuizID,Quiz_Name from Quiz_Master order by QuizID";
OleDbDataReader dr = cmd.ExecuteReader();
lstQuizName.Items.Clear();
lstQuizName.BeginUpdate();
while (dr.Read())
{
lstQuizName.Items.Add(dr.GetString(1));
}
lstQuizName.EndUpdate();
dr.Close();
newcon.Close();
}
catch
{
}
}
private OleDbConnection TheConnection()
{
OleDbConnection conn = new OleDbConnection();
string Connstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Quiz Software\\QuizDB.mdb";
conn.ConnectionString = Connstring;
conn.Open();
return conn;
}
private void btnOK_Click(object sender, EventArgs e)
{
string aa="";
string selctdVal = lstQuizName.SelectedItem.ToString();
OleDbConnection dbconn = TheConnection();
OleDbDataAdapter dadpter = new OleDbDataAdapter("Select QuizID from Quiz_Master where Quiz_Name = '" + selctdVal.Trim() + "'", dbconn);
DataSet ds = new DataSet();
dadpter.Fill(ds, "Quiz_Master");
DataTable dt = ds.Tables[0];
if(dt.Rows[0]["QuizID"].ToString() != string.Empty)
{
aa = dt.Rows[0]["QuizID"].ToString();
}
frmQuizName ff = new frmQuizName(aa, selctdVal);
ff.Show();
Close();
}
private void btncancel_Click(object sender, EventArgs e)
{
Close();
}
}
}
Any help in this regard will be appreciated. I am not familiar with Windows application..
Thanks in advance.
|

October 17th, 2009, 07:17 AM
|
 |
Wrox Author
Points: 33,554, Level: 80 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 Posts
|
|
Quote:
|
It seems everyone in this forum works on Web Applications and I haven't found anyone helping out with Windows Applications . That's a pity.
|
Well, you posted this in an ASP.NET forum, so it's no surprise people here work with Web Applications, You're better off picking a different category for Win Form related questions, like this one: http://p2p.wrox.com/other-net-463/
Cheers,
Imar
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |