You must Sign In to post a response.
  • Category: .NET

    How to check button clicked or not on form?

    Hello ,
    I have 1 form says A . I want to perform a task in which form A executing some part of a code which is needed to be execute on button click on same form . Control should wait in that case till button click and after button clicked, bellow code should executes.

    Following is my code :

    private void button1_Click_1(object sender, EventArgs e) //send button//
    {
    try
    {
    List<DataGridViewRow> rows_with_checked_column = new List<DataGridViewRow>();
    foreach (DataGridViewRow row in dataGridView1.Rows)
    {
    if (Convert.ToBoolean(row.Cells[Column4.Name].Value) == true)
    {
    rows_with_checked_column.Add(row);
    }
    }
    foreach (DataGridViewRow row in dataGridView1.Rows)
    {
    if (Convert.ToBoolean(row.Cells[Column4.Name].Value) == true)
    {
    for (int i = 0; i <= row.Cells.Count - 1; i++)
    {
    row.Cells[i].Style.BackColor = Color.Aqua;
    // data = row.Cells[1].Value.ToString();
    }
    }
    row.Cells[Column4.Name].Value = false;
    }
    }
    catch { }
    }

    The method::

    case "_":
    if (res.StartsWith("_"))
    {
    System.Windows.Forms.MessageBox.Show("Send indent to Device");
    unscr = Encoding.ASCII.GetBytes("@!#");
    networkStream.Write(unscr, 0, unscr.Length);

    if (//conditin that checks button1wasclicked or not//)
    {
    string d = ifile.IniReadValue("Config Section", "INDENT_NO");
    unscr = Encoding.ASCII.GetBytes("!" + data);
    networkStream.Write(unscr, 0, unscr.Length);
    hash = Encoding.ASCII.GetBytes("#");
    networkStream.Write(hash, 0, hash.Length);
    }
    else
    { return; //this should go in same case to be executes };
    }


    I have tried by setting bool value false while declare and make it true in event , and then use it in method but after leaving the event it again gets false value. help someone. thanks!!
  • #763238
    Hi,

    As per my understand the post you want to execute some event in the mean time of performing some other action.

    Since you are using boolean property after postback value gets changed and default value will assign back to that control, I request you to please use viewstate object to maintain state of the control, for validating whether event is clicked or not.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #763258
    Hello Priyanka Barwad,

    You can achieve this by doing below code :

    private void ButtonSave_Click(object sender, EventArgs e)
    {
    // Write your code here
    }

    private void ButtonSavePrint_Click(object sender, EventArgs e)
    {
    DialogResult ans;
    ans = MessageBox.Show("Are you sure?", "Save & Print", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
    if (ans == DialogResult.Yes)
    {
    try
    {
    ButtonSave_Click(ButtonSave, null);
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    finally
    {

    }
    }
    }

    On ButtonSavePrint Click event you can call ButtonSave Click event by answering yes on messagebox button.


    Hope this is what you are looking for.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"


Sign In to post your comments