Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 2 của 2
  1. #1
    Ngày tham gia
    Sep 2015
    Bài viết
    0

    Window Form, lỗi về method Select()

    MOD Delete dùm nhé. Thanks!



    Mình có code ntn



    Mã:
    string InsertedID = textBoxID.Text;
                try
                {
                    int IntID = Convert.ToInt32(InsertedID);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Put in a number, please!");
    
                }
                finally
                {
    
                    textBoxID.Select();
                    //this.Close();
                    if (textBoxPlace.Text == "")
                    {
                        MessageBox.Show("Please fill the Place", "Error");
                        textBoxPlace.Focus();
                    }
                    string InsertedPlace = textBoxPlace.Text;
                }
    Đại khái là sau khi catch Exception thì phải chạy textBoxID.Select(); nhưng mà mình compile thì nó đã bị ignore, ko hiểu tại sao
    Giúp mình với. Thanks in advance! (sorry if my question is stupid )

  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    hình như cái logic của bạn có vấn đề rồi ... textbox select là Select All ??

    finally { nghĩa là regardless exception hay không exception nó điều chạy vào hết.

    thử:

    int id = 0;
    string InsertedPlace;
    try
    {
    id = Convert.ToInt32(textBoxID.Text);
    if (string.isNullOrEmpty(textBoxPlace.Text))
    {
    MessageBox.Show("Please fill the Place", "Error");
    textBoxPlace.Focus();
    return;
    }
    else {
    InsertedPlace = textBoxPlace.Text;
    }
    }
    catch (Exception ex)
    {
    MessageBox.Show("Put in a number, please!");
    return;
    }
    finally
    {


    }

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •