Hello,
I have form1 with various databound textboxes (customer details) and a working customers_binding_navigator plus datasets.
A button on form1 named btnSearch opens form2.ShowDialog that has working search functionality and returns queried records into a datagridview.
Q: I want to use a "dataGridView_RowHeaderMouseDoubleClick" event to close the form2 and get my form1 to show the records relating to the dataGridView selected result .
Ie: if the user chooses a record in datagridview that is "Mr jones with contact ID = 4" how will form1 refresh and show Mr Jones contact details.
What are the steps as I am quite lost.
Thanks in advance
Jan MontanoPosted Jan 6, 2009, 9:01 PM
Let's say you want the record with contactid 9 (assuming contactid is your primary key):
Additional link: BindingSource and BindingNavigator in C# 2.0
you need to expose a ContactID property on form2.
form2.cs
----------------
public int ContactID // assuming the data type of your contactID is int
{
get { return contactID; }
}
private int contactID;
// you told me you could get the contactID and used the messagebox to display it.on that line of code, assign the contact id value you got instead to the variable contactID;
contactID = // specify value here
I assume you displayed form2 by calling form2.ShowDialog(); you need to set the position after the form2 closes
form1.cs
...
------------------------
Manuel BPosted Jan 7, 2009, 3:19 PM
THANK YOU very, very much.
Really appreciated because without your answer I would not have made progress.
Ciao
Manuel BPosted Jan 6, 2009, 3:41 PM
Dragged a binding navigator onto my Form and C# 2008 express did the work.
Found these as you asked:
on form1.cs:
private
void customersBindingNavigatorSaveItem_Click_1(object sender, EventArgs e){
this.Validate(); this.customersBindingSource.EndEdit(); this.tableAdapterManager.UpdateAll(this.studioDentDataSet);}
on form1.designer.cs
//
// customersBindingNavigator // this.customersBindingNavigator.AddNewItem = this.bindingNavigatorAddNewItem; this.customersBindingNavigator.BindingSource = this.customersBindingSource; this.customersBindingNavigator.CountItem = this.bindingNavigatorCountItem; this.customersBindingNavigator.CountItemFormat = "di {0}"; this.customersBindingNavigator.DeleteItem = this.bindingNavigatorDeleteItem; this.customersBindingNavigator.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.bindingNavigatorMoveFirstItem, this.bindingNavigatorMovePreviousItem, this.bindingNavigatorSeparator, this.bindingNavigatorPositionItem, this.bindingNavigatorCountItem, this.bindingNavigatorSeparator1, this.bindingNavigatorMoveNextItem, this.bindingNavigatorMoveLastItem, this.bindingNavigatorSeparator2, this.bindingNavigatorAddNewItem, this.bindingNavigatorDeleteItem, this.customersBindingNavigatorSaveItem, this.toolTipRefresh}); this.customersBindingNavigator.Location = new System.Drawing.Point(0, 24); this.customersBindingNavigator.MoveFirstItem = this.bindingNavigatorMoveFirstItem; this.customersBindingNavigator.MoveLastItem = this.bindingNavigatorMoveLastItem; this.customersBindingNavigator.MoveNextItem = this.bindingNavigatorMoveNextItem; this.customersBindingNavigator.MovePreviousItem = this.bindingNavigatorMovePreviousItem; this.customersBindingNavigator.Name = "customersBindingNavigator"; this.customersBindingNavigator.PositionItem = this.bindingNavigatorPositionItem; this.customersBindingNavigator.Size = new System.Drawing.Size(668, 25); this.customersBindingNavigator.TabIndex = 1; this.customersBindingNavigator.Text = "bindingNavigator1"; // // bindingNavigatorAddNewItem // this.bindingNavigatorAddNewItem.Image = ((System.Drawing.Image)(resources.GetObject("bindingNavigatorAddNewItem.Image"))); this.bindingNavigatorAddNewItem.Name = "bindingNavigatorAddNewItem"; this.bindingNavigatorAddNewItem.RightToLeftAutoMirrorImage = true; this.bindingNavigatorAddNewItem.Size = new System.Drawing.Size(94, 22); this.bindingNavigatorAddNewItem.Text = "Nuovo Cliente"; this.bindingNavigatorAddNewItem.ToolTipText = "Aggiunge un nuovo cliente nel sistema"; this.bindingNavigatorAddNewItem.Click += new System.EventHandler(this.bindingNavigatorAddNewItem_Click); // // customersBindingSource // this.customersBindingSource.DataMember = "Customers"; this.customersBindingSource.DataSource = this.studioDentDataSet; // // studioDentDataSet // this.studioDentDataSet.DataSetName = "StudioDentDataSet"; this.studioDentDataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema; // // bindingNavigatorCountItem // this.bindingNavigatorCountItem.Name = "bindingNavigatorCountItem"; this.bindingNavigatorCountItem.Size = new System.Drawing.Size(34, 22); this.bindingNavigatorCountItem.Text = "di {0}"; this.bindingNavigatorCountItem.ToolTipText = "Total number of items"; // // bindingNavigatorDeleteItem // this.bindingNavigatorDeleteItem.Image = ((System.Drawing.Image)(resources.GetObject("bindingNavigatorDeleteItem.Image"))); this.bindingNavigatorDeleteItem.Name = "bindingNavigatorDeleteItem"; this.bindingNavigatorDeleteItem.RightToLeftAutoMirrorImage = true; this.bindingNavigatorDeleteItem.Size = new System.Drawing.Size(100, 22); this.bindingNavigatorDeleteItem.Text = "Rimuovi Cliente"; this.bindingNavigatorDeleteItem.ToolTipText = "Elimina definitivamente questo cliente"; // // bindingNavigatorMoveFirstItem // this.bindingNavigatorMoveFirstItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.bindingNavigatorMoveFirstItem.Image = ((System.Drawing.Image)(resources.GetObject("bindingNavigatorMoveFirstItem.Image"))); this.bindingNavigatorMoveFirstItem.Name = "bindingNavigatorMoveFirstItem"; this.bindingNavigatorMoveFirstItem.RightToLeftAutoMirrorImage = true; this.bindingNavigatorMoveFirstItem.Size = new System.Drawing.Size(23, 22); this.bindingNavigatorMoveFirstItem.Text = "Move first"; // // bindingNavigatorMovePreviousItem // this.bindingNavigatorMovePreviousItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.bindingNavigatorMovePreviousItem.Image = ((System.Drawing.Image)(resources.GetObject("bindingNavigatorMovePreviousItem.Image"))); this.bindingNavigatorMovePreviousItem.Name = "bindingNavigatorMovePreviousItem"; this.bindingNavigatorMovePreviousItem.RightToLeftAutoMirrorImage = true; this.bindingNavigatorMovePreviousItem.Size = new System.Drawing.Size(23, 22); this.bindingNavigatorMovePreviousItem.Text = "Move previous"; // // bindingNavigatorSeparator // this.bindingNavigatorSeparator.Name = "bindingNavigatorSeparator"; this.bindingNavigatorSeparator.Size = new System.Drawing.Size(6, 25); // // bindingNavigatorPositionItem // this.bindingNavigatorPositionItem.AccessibleName = "Position"; this.bindingNavigatorPositionItem.AutoSize = false; this.bindingNavigatorPositionItem.Name = "bindingNavigatorPositionItem"; this.bindingNavigatorPositionItem.Size = new System.Drawing.Size(50, 21); this.bindingNavigatorPositionItem.Text = "0"; this.bindingNavigatorPositionItem.ToolTipText = "Current position"; // // bindingNavigatorSeparator1 // this.bindingNavigatorSeparator1.Name = "bindingNavigatorSeparator1"; this.bindingNavigatorSeparator1.Size = new System.Drawing.Size(6, 25); // // bindingNavigatorMoveNextItem // this.bindingNavigatorMoveNextItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.bindingNavigatorMoveNextItem.Image = ((System.Drawing.Image)(resources.GetObject("bindingNavigatorMoveNextItem.Image"))); this.bindingNavigatorMoveNextItem.Name = "bindingNavigatorMoveNextItem"; this.bindingNavigatorMoveNextItem.RightToLeftAutoMirrorImage = true; this.bindingNavigatorMoveNextItem.Size = new System.Drawing.Size(23, 22); this.bindingNavigatorMoveNextItem.Text = "Move next"; // // bindingNavigatorMoveLastItem // this.bindingNavigatorMoveLastItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.bindingNavigatorMoveLastItem.Image = ((System.Drawing.Image)(resources.GetObject("bindingNavigatorMoveLastItem.Image"))); this.bindingNavigatorMoveLastItem.Name = "bindingNavigatorMoveLastItem"; this.bindingNavigatorMoveLastItem.RightToLeftAutoMirrorImage = true; this.bindingNavigatorMoveLastItem.Size = new System.Drawing.Size(23, 22); this.bindingNavigatorMoveLastItem.Text = "Move last"; // // bindingNavigatorSeparator2 // this.bindingNavigatorSeparator2.Name = "bindingNavigatorSeparator2"; this.bindingNavigatorSeparator2.Size = new System.Drawing.Size(6, 25); // // customersBindingNavigatorSaveItem // this.customersBindingNavigatorSaveItem.Image = ((System.Drawing.Image)(resources.GetObject("customersBindingNavigatorSaveItem.Image"))); this.customersBindingNavigatorSaveItem.Name = "customersBindingNavigatorSaveItem"; this.customersBindingNavigatorSaveItem.Size = new System.Drawing.Size(53, 22); this.customersBindingNavigatorSaveItem.Text = "Salva"; this.customersBindingNavigatorSaveItem.Click += new System.EventHandler(this.customersBindingNavigatorSaveItem_Click_1); //Thanks for your time
Jan MontanoPosted Jan 5, 2009, 7:50 PM
Manuel BPosted Jan 5, 2009, 12:40 PM
Hi and thanks for the reply.
Tried to plug in your code but I get a whole lot of unhandled exception errors.
I tried a few things in the mean time and am getting close so now I ask you if you can help me proceed forward.
I discovered the currentCell method...
private
void dataGridView1_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e){
MessageBox
.Show(dataGridView1.CurrentCell.Value.ToString());}
this gets my contact ID number into a message box so I could understand if the value was good...
If only I was able to get all my form1 databound textboxes to update themselves to this contactID value upon form2.close I would be happy.
So, after the form2 close event what should I code and where? Do I feed this value into the binding navigator or do I do a new sqlcommand query.
This programming story is making me crazy.....
Been trying for 4 months but am not making much progress so please write out explanation like you were talking to a newbie cos I am worse.
Thanks in advance
Jan MontanoPosted Jan 4, 2009, 9:23 PM
Form 2
--------
public DataGridViewRow SelectedRow
{
get { return selectedRow; }
}
private DataGridViewRow selectedRow = null;
private void dataGridView_RowHeaderMouseDoubleClick(... )
{
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
this.Close();
}
Form1
-------
private void btnSearchClick(... )
{
Form2 form2 = new Form2();
form2.ShowDialog();
// access property of form2.
DataGridViewRow row = form2.SelectedRow;
// now you have the selected data and you could display whatever it is you need to display.
}