Hi,
I have a Main Form which is the parent form.I open Form1 inside the parent form and Form1 has a textbox textbox1.On textbox1_textchanged event i should open Form2 and pass a value to it keeping Form1 opened.Depending upon that value the datagridview on Form2 gets populated.Up to here it is fine.Now what i need is when i leave the Textbox1(ie,textbox1_leave event) i should close the Form2.How can i acheive that
My code for Textchanged event in Form1 is
private void textBox1_TextChanged(object sender, EventArgs e)
{
bookname = textBox1.Text;
Form2 obj = new Form2();
obj.Show();
textBox1.Focus();
}
Thanks in advance
Loading
VulpesPosted Dec 2, 2012, 10:06 AM
ullas KPosted Apr 12, 2013, 5:15 AM
I have a Datagridview with Columns Product Name, Unit Price,Qty ,Total and Status.Status column is invisible. The value of Status Column will be "Y" or "N" depending upon the Product which is fetched from the database.What i need is to get the Grand total of Products with Status="Y" in Textbox1 and the Total of Products with Status="N" in TextBox2. This is what i should get when i enter value in QTY column
Product Unit Price Qty Total Status
A 10 2 20.00 Y
B 20 1 20.00 N
C 50 2 100.00 Y
D 30 1 30.00 Y
E 25 1 25.00 N
TextBox1=150.00
TextBox2= 45.00
How to acheive this.Pls help and thanks in advance
Phani RajPosted Dec 29, 2012, 10:56 AM
VulpesPosted Dec 5, 2012, 5:02 AM
ullas KPosted Dec 5, 2012, 5:00 AM
to my PopulateDGVEX1Row method and after that i inserted a new row
Now it is working as desired
Once again thanks for your support
VulpesPosted Dec 5, 2012, 4:53 AM
dataGridViewEx1.Rows.Add();
ullas KPosted Dec 4, 2012, 8:08 PM
VulpesPosted Dec 4, 2012, 3:30 PM
dataGridViewEx1.RowCount++;
ullas KPosted Dec 4, 2012, 3:15 AM
Can you please help me to solve out this.I have asked this question but have'nt received an answer yet.
i have a datagridview in Form1 with columns Sl.No , Book no,Book name ,issue date, due date.
when i Enter a book no in Book No column, then all the details of the books
are populated in other columns of datagridview and a new row is added automatically (Datagridview changes to edit mode)where i can enter other book no in book no column of that row to get its details displayed and so on .
For this to happen i am writing my code in Cell Value changed event of datagridview
My code is
private void dataGridViewEx1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1)
{
if (dataGridViewEx1.Rows[e.RowIndex].Cells[1].Value != null)
{
con = db.open();
BookNumber = dataGridViewEx1.CurrentRow.Cells[1].Value.ToString();
SqlDataAdapter adp = new SqlDataAdapter("SELECT E_NAME FROM BOOKS WHERE BOOK_NO='" + BookNumber.ToString() + "' ", con);
DataSet ds = new DataSet();
adp.Fill(ds, "s");
if (ds.Tables["s"].Rows.Count >= 1)
{
dataGridViewEx1.CurrentRow.Cells[2].Value = ds.Tables["s"].Rows[0].ItemArray[0];
SendKeys.Send("{TAB}");
SendKeys.Send("{TAB}");
SendKeys.Send("{TAB}");
dataGridViewEx1.CurrentRow.Cells[3].Value = DateTime.Now;
dataGridViewEx1.CurrentRow.Cells[4].Value = DateTime.Now.AddDays(holddays);
}
else
{
MessageBox.Show("No Such Book Exists.Please check the Book Number", "easyLib", MessageBoxButtons.OK);
SendKeys.Send("{left}");
}
db.close();
}
}
}
This is working fine.
Now consider a situation where i do not know the book No to enter.In such a situation i have written code to display all the book No ,Book Name details in a datagridview
in other form(Say FORM2). when i press F1 key in Book No column in Form1
form2 is displayed. i select the required book no from Form2 and when i press enter that book no should be displayed in my Form1 book no column.I was able to do that.For that My code in Form1 is
internal void PopulateDGVEX1Row(string prodCode )
{
con = db.open();
dataGridViewEx1.CurrentRow.Cells[1].Value = prodCode.ToString();
SqlDataAdapter adp = new SqlDataAdapter("SELECT E_NAME FROM BOOKS WHERE BOOK_NO='" + prodCode.ToString() + "' ", con);
DataSet ds = new DataSet();
adp.Fill(ds, "s");
if (ds.Tables["s"].Rows.Count >= 1)
{
// dataGridViewEx1.CurrentRow.Cells[1].Value = ds.Tables["s"].Rows[0].ItemArray[0];
dataGridViewEx1.CurrentRow.Cells[2].Value = ds.Tables["s"].Rows[0].ItemArray[0];
SendKeys.Send("{TAB}");
SendKeys.Send("{TAB}");
SendKeys.Send("{TAB}");
dataGridViewEx1.CurrentRow.Cells[3].Value = DateTime.Now;
dataGridViewEx1.CurrentRow.Cells[4].Value = DateTime.Now.AddDays(holddays);
}
else
{
MessageBox.Show("No Such Book Exists.Please check the Book Number", "easyLib", MessageBoxButtons.OK);
SendKeys.Send("{left}");
}
dataGridViewEx1.RefreshEdit();
db.close();
}
and in Form2 my code is
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F1)
{
prodCode = dataGridView1.CurrentRow.Cells[0].Value.ToString();
f1.PopulateDGVEX1Row(prodCode);
this.Dispose();
this.Close();
}
}
I am getting the Book No in Form1 and its details in other Columns.But My problem is in this case a new row is not added in Form1 when i am getting book no from Form2 unless i enter any value in a datagridview cell in form1.(When i enter a Book No in Column1 a new row is added and i was able to add another book no).How can i make it add a new row automatically to datagridview in Form1 when i get book no from other form(Form2).ie i should be able to work in both ways.If i know the book no it's ok but for those which i do not know i should fetch it from other form and should get a new row added in case if there is more book details to be entered
How can i do this .
Thanks in advance
Pravin GhadgePosted Dec 3, 2012, 8:25 AM
Form2 obj;
private void textBox1_TextChanged(object sender, EventArgs e)
{
bookname = textBox1.Text;
obj = new Form2();
obj.Show();
textBox1.Focus();
}
private void textBox1_Leave(object sender, EventArgs e)
{
bookname = textBox1.Text;
if (obj!=null)
{
obj = new Form2();
obj.Close();
}
}
ullas KPosted Dec 3, 2012, 5:27 AM
VulpesPosted Dec 3, 2012, 5:17 AM
ullas KPosted Dec 3, 2012, 4:11 AM
In the Form_load event of form2 my code is as follows
string bookname = form1.bname();
string catcode = form1.category();
LibraryLib.Library obj = new LibraryLib.Library();
DataTable dt;
dt = obj.select("select Book_no, E_Name from Books where E_Name like'" + bookname.ToUpper() + "%' and Catcode='"+catcode+"'");
dataGridView1.DataSource = dt;
dataGridView1.Refresh();