Finally,I have solved my problem. but there is only one issue which i want to finalize with u.
I have defined toolStrip and used toolStrip button and toolStripDropDownButton1 in the Form.
And I use this following logic which is working fine for me
private void DisableButton()
{
tbRef.Visible = false;
tbGet.Visible = false;
tbSave.Visible = false;
tbEdit.Visible = false;
tbDel.Visible = false;
toolStripDropDownButton1.Visible = false;
}
private void GetControl()
{
this.Text = "Student Registeration";
string form = this.Text;
string name = null;
string controls = null;
foreach (DataGridViewRow items in dGVR.Rows)
{
string module = items.Cells[2].Value.ToString();
string control = items.Cells[3].Value.ToString();
bool status = Convert.ToBoolean(items.Cells[4].Value.ToString());
name = module.ToString();
controls = control.ToString();
if (form == name)
{
if (tbSave.Text == controls)
{
tbSave.Visible = true;
}
if (tbEdit.Text == controls)
{
tbEdit.Visible = true;
}
if (tbDel.Text == controls)
{
tbDel.Visible = true;
}
if (tbRef.Text == controls)
{
tbRef.Visible = true;
}
if (tbGet.Text == controls)
{
tbGet.Visible = true;
}
if (toolStripDropDownButton1.Text == controls)
{
toolStripDropDownButton1.Visible = true;
}
}
}
if (form != name)
{
MessageBox.Show("Contact your Administrator", "Message", MessageBoxButtons.OK, MessageBoxIcon.Stop);
this.Close();
}
}
It is working for me but I want to use the code like the following way
foreach (ToolStripDropDownItem item in menuStrip1.Items)
{
item.Visible = false;
if (item.Text == name)
{
item.Visible = true;
}
}
Instead of
if (form == name)
{
if (tbSave.Text == controls)
{
tbSave.Visible = true;
}
if (tbEdit.Text == controls)
{
tbEdit.Visible = true;
}
if (tbDel.Text == controls)
{
tbDel.Visible = true;
}
if (tbRef.Text == controls)
{
tbRef.Visible = true;
}
if (tbGet.Text == controls)
{
tbGet.Visible = true;
}
if (toolStripDropDownButton1.Text == controls)
{
toolStripDropDownButton1.Visible = true;
}
}
Is there any solution for required output????