hope any can help in me this,
i have a datagridview and and tabcontrol,
tabcontrol has three tab pages,
tabPage_add,tabPage_edit and tabPage_view,
tabPage_add for adding the records,
tabPage_edit for editing and updating,
tabPage_view for Viewing,
in tabPage_view i have datagridview as 'dataGridView1'
i am bounding that gridView Data in a function called SetDataGridViewData()
i have added the Columns of dataGridView1 and have put their DisplayPropertyName to the Corresponding Columns of Database Table,
now
my need is that, if i want to edit the particular record in dataGridView1 then first the row of dataGridView1 must be selected and then can be navigated to tabPage_edit, the tabControl1_Selected Event Handler is like this
private void tabControl1_Selected(object sender, TabControlEventArgs e)
{
if (e.TabPage.Text.ToLower() == "add")
{
e.TabPage.Controls.Clear();
setForAdd();
e.TabPage.Controls.Add(tableLayoutPanel1);
}
else if (e.TabPage.Text.ToLower() == "edit")
{
e.TabPage.Controls.Clear();
setForEdit();
e.TabPage.Controls.Add(tableLayoutPanel1);
}
else
{
setDataGridViewData();
}
}
where setForEdit() is like this
void setForEdit()
{
if (dataGridView1.SelectedRows.Count > 0)
{
btn_add.Visible = false;
btn_delete.Visible = true;
btn_update.Visible = true;
lbl_subhead.Text = "Edit Available Drug";
setPanelById(dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
}
else
tabControl1.SelectedIndex = 2;
}
the code for setForAdd() is like this
void setForAdd()
{
btn_add.Visible = true;
btn_delete.Visible = false;
btn_update.Visible = false;
lbl_subhead.Text = "Add Available Drug";
setEmptyScreenFields();
setId();
}
the code of dataGridView1 in the designer.cs is as
this.dataGridView1.AllowUserToAddRows = false;
this.dataGridView1.AllowUserToDeleteRows = false;
this.dataGridView1.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Column_id,
this.Column_name,
this.Column_type,
this.Column_mnfrid,
this.Column_expiryDate});
this.dataGridView1.ContextMenuStrip = this.contextMenuStrip1;
this.dataGridView1.Location = new System.Drawing.Point(150, 166);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.ReadOnly = true;
this.dataGridView1.Size = new System.Drawing.Size(627, 340);
this.dataGridView1.TabIndex = 2;
this.dataGridView1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.dataGridView1_MouseDown);
the remaining are doing exactly needed operations
thanx if somebody can help me.......