单击标题时,Datagridview崩溃。 [英] Datagridview crashes when header is clicked.

查看:91
本文介绍了单击标题时,Datagridview崩溃。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我点击datagridview的标题,它会崩溃。我不知道如何解决它。我收到此错误:



mscorlib.dll中发生System.ArgumentOutOfRangeException类型的未处理异常



补充信息:指数超出范围。必须是非负数且小于集合的大小。



此时崩溃:

  private   void  dgvProfiles_CellClick( object  sender ,DataGridViewCellEventArgs e)
{indexRow = e.RowIndex; // 获取所选行索引
DataGridViewRow row = dgvProfiles.Rows [indexRow ];
}





我的尝试:



我试图编辑DataGridViewRow row = dgvProfiles.Rows [indexRow],但似乎没什么用。



 命名空间 ProfileManager 
{
public partial class Form1:Form

{
DataTable dt = < span class =code-keyword> new DataTable();
private int indexRow;

public Form1()
{
InitializeComponent();
}

private void Form1_Load( object sender,EventArgs e)
{
dt.Columns.AddRange( new DataColumn [ 8 ]
{ new DataColumn( ID typeof string )) ,
new DataColumn( 名字 typeof string )),
new DataColumn( 姓氏 typeof stri ng )),
new DataColumn( 电话 typeof string )),
< span class =code-keyword> new DataColumn( Email typeof string )),
new DataColumn( City typeof string )),
new DataColumn( 状态 typeof string )),
new DataColumn( Zip typeof 字符串))});

}

private void btnAdd_Click(< span class =code-keyword> object
sender,EventArgs e)
{
if String .IsNullOrEmpty(txtID.Text))
{
MessageBox.Show( 请填写ID Name字段。);
}

其他 如果
String .IsNullOrEmpty(txtFirstName.Text))
{
MessageBox.Show( < span class =code-string>请填写名字字段。);
}

else if String .IsNullOrEmpty(txtLastName.Text))
{
MessageBox.Show( 请填写姓氏字段。);
}


其他 如果 String .IsNullOrEmpty(txtPhone.Text))
{
MessageBox.Show( < span class =code-string>请填写电话字段。);
}

else if String .IsNullOrEmpty(txtEmail.Text))
{
MessageBox.Show( 请填写电子邮件字段。);
}

else if String .IsNullOrEmpty(txtCity.Text))
{
MessageBox.Show( 请填写City字段。);
}
其他 如果 String .IsNullOrEmpty(cbxState.Text))
{
MessageBox.Show( 请填写州领域。);
}
其他 如果 String .IsNullOrEmpty(txtZip.Text))
{
MessageBox.Show( 请填写邮政编码字段。);
}

其他 {
for (< span class =code-keyword> int row = 0 ; row < dgvProfiles .Rows.Count; row ++)
{
for int col = < span class =code-digit> 0 ; col < dgvProfiles.Columns.Count; col ++)
{
< span class =code-keyword> if (dgvProfiles.Rows [row] .Cells [col] .Value!= null &&
dgvProfiles.Rows [row] .Cells [col] .Value.Equals(txtEmail.Text.Trim()))
{
MessageBox.Show( 输入了重复的电子邮件。);
return ;
}

else if (dgvProfiles.Rows [row] .Cells [col] .Value!= null &&
dgvProfiles.Rows [row] .Cells [col] .Value.Equals(txtID。 Text.Trim()))
{
MessageBox.Show( 输入了重复的ID。 );
return ;

}
}
}

dt.Rows.Add(txtID.Text,txtFirstName.Text,txtLastName.Text,txtPhone.Text,txtEmail .Text,txtCity.Text,cbxState.Text,txtZip.Text);
this .dgvProfiles.DataSource = dt;
txtID.Text = ;
txtFirstName.Text = ;
txtLastName.Text = ;
txtPhone.Text = ;
txtEmail.Text = ;
txtPhone.Text = ;
txtCity.Text = ;
cbxState.SelectedIndex = -1;
txtZip.Text = ;
MessageBox.Show( 记录已成功添加。);
}



}


私人 < span class =code-keyword> void
dataGridView1_CellContentClick( object sender,DataGridViewCellEventArgs e)
{

}

private void btnClear_Click( object sender,EventArgs e)
{
DialogResult dialog = MessageBox.Show( 您确定要清除每个字段吗?所有数据都将丢失! 清除 ,MessageBoxButtons.YesNo);
if (dialog == DialogResult.Yes)
{
txtID.Text = ;
txtFirstName.Text = ;
txtLastName.Text = ;
txtPhone.Text = ;
txtEmail.Text = ;
txtCity.Text = ;
cbxState.SelectedIndex = -1;
txtZip.Text = ;
dt.Rows.Clear();
}

其他 {
return ;
}

}

private void btnClose_Click( object sender,EventArgs e)
{
DialogResult dialog = MessageBox.Show( 您确定要关闭吗?所有数据都将丢失! 退出,MessageBoxButtons.YesNo);
if (dialog == DialogResult.Yes)
{
Application.Exit();
}

else
{
return ;
}
}


私人 void txtFirstName_KeyPress( object sender,KeyPressEventArgs e)
{
e.Handled =!( char .IsLetter(e.KeyChar)|| e.KeyChar ==( char )Keys.Back);
}

private void txtLastName_KeyPress( object sender,KeyPressEventArgs e)
{
e.Handled =!( char .IsLetter(e。 KeyChar)|| e.KeyChar ==( char )Keys.Back);
}

private void txtCity_KeyPress( object sender,KeyPressEventArgs e)
{
e.Handled =!( char .IsLetter(e。 KeyChar)|| e.KeyChar ==( char )Keys.Back);
}

private void groupBox1_Enter( object sender,EventArgs e)
{

}

private void btnDelete_Click( object sender,EventArgs e)
{
if (dgvProfiles.SelectedCells.Count < = 0
{
MessageBox.Show( 请选择您要删除的记录。 );
}


其他 {
foreach (DataGridViewCell oneCell in dgvProfiles.SelectedCells)
{
if (oneCell .Selected)
{
dgvProfiles.Rows.RemoveAt(oneCell.RowIndex);
MessageBox.Show( 记录已成功删除!);
break ;
}

else if (oneCell.RowIndex < = 0
{
MessageBox.Show( 请选择您要删除的记录);
}
}

}

}

private void btnUpdate_Click( object sender,EventArgs e)
{
if (dgvProfiles.SelectedCells.Count < = 0
{
MessageBox.Show( 未选择任何记录进行更新。);
}

其他 {
for (< span class =code-keyword> int
row = 0 ; row < dgvProfiles .Rows.Count; row ++)
{
for int col = < span class =code-digit> 0
; col < dgvProfiles.Columns.Count; col ++)
{
< span class =code-keyword> if (dgvProfiles.Rows [row] .Cells [col] .Value!= null &&
dgvProfiles.Rows [row] .Cells [col] .Value.Equals(txtEmail.Text.Trim()))
{
MessageBox.Show( 输入了重复的电子邮件。);
return ;
}

else if (dgvProfiles.Rows [row] .Cells [col] .Value!= null &&
dgvProfiles.Rows [row] .Cells [col] .Value.Equals(txtID。 Text.Trim()))
{
MessageBox.Show( 输入了重复的ID。 );
return ;

}
}
}
DataGridViewRow newDataRow = dgvProfiles.Rows [indexRow];
newDataRow.Cells [ 0 ]。Value = txtID.Text;
newDataRow.Cells [ 1 ]。Value = txtFirstName.Text;
newDataRow.Cells [ 2 ]。Value = txtLastName.Text;
newDataRow.Cells [ 3 ]。Value = txtPhone.Text;
newDataRow.Cells [ 4 ]。Value = txtEmail.Text;
newDataRow.Cells [ 5 ]。Value = txtCity.Text;
newDataRow.Cells [ 6 ]。Value = cbxState.Text;
newDataRow.Cells [ 7 ]。Value = txtZip.Text;

}
}

private void dgvProfiles_CellClick( object sender,DataGridViewCellEventArgs e)
{
indexRow = e.RowIndex; // 获取选定的行索引
DataGridViewRow row = dgvProfiles.Rows [indexRow];

txtID.Text = row.Cells [ 0 ]。Value.ToString();
txtFirstName.Text = row.Cells [ 1 ]。Value.ToString();
txtLastName.Text = row.Cells [ 2 ]。Value.ToString();
txtPhone.Text = row.Cells [ 3 ]。Value.ToString();
txtEmail.Text = row.Cells [ 4 ]。Value.ToString();
txtCity.Text = row.Cells [ 5 ]。Value.ToString();
cbxState.Text = row.Cells [ 6 ]。Value.ToString();
txtZip.Text = row.Cells [ 7 ]。Value.ToString();

}

private void txtEmail_Validating(< span class =code-keyword> object
sender,CancelEventArgs e)
{
System.Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex( @ ^ [a-zA-Z] [\\\\ .-] * [A-ZA-Z0-9] @ [A-ZA-Z0-9] [\w\ .-] * [A-ZA-Z0-9] \。[A-ZA- Z] [A-ZA-Z\] * [A-ZA-Z] $)。
if (txtEmail.Text.Length > 0
{
if (!rEMail.IsMatch(txtEmail.Text))
{
MessageBox.Show( 需要电子邮件 错误,MessageBoxButtons.OK,MessageBoxIcon.Error);
txtEmail.SelectAll();
e.Cancel = true ;
}
}
}

private void txtPhone_Validating( object sender,CancelEventArgs e)
{
System.Text.RegularExpressions.Regex rPhone = new System.Text.RegularExpressions.Regex( @ (\ + \d { 1,2} \s)\?(?\d {3} \)?[\s .-] \d {3} [\s .-] \d {4 } $);
if (txtPhone.Text.Length > 0
{
if (!rPhone.IsMatch(txtPhone.Text))
{
MessageBox.Show( 需要有效的电话号码 错误,MessageBoxButtons.OK,MessageBoxIcon.Error);
txtPhone.SelectAll();
e.Cancel = true ;
}
}
}

private void txtZip_Validating( object sender,CancelEventArgs e)
{
System.Text.RegularExpressions.Regex rZip = new System.Text.RegularExpressions.Regex( @ (^ \d {5} (-\d {4})?$)|(^ [ABCEGHJKLMNPRSTVXYabceghjklmnprstvxy] {1} \d {1} [ABCEGHJKLMNPRSTVWXYZabceghjklmnprstv xy] {1} * \d {1} [ABCEGHJKLMNPRSTVWXYZabceghjklmnprstvxy] {1} \ d {1} $));
if (txtZip.Text.Length > 0
{
if (!rZip.IsMatch(txtZip.Text))
{
MessageBox.Show( 需要有效的拉链。必须是5位数格式。,< span class =code-string>
错误,MessageBoxButtons.OK,MessageBoxIcon.Error);
txtZip.SelectAll();
e.Cancel = true ;
}
}

}

private void txtPhone_KeyPress( object sender,KeyPressEventArgs e)
{
char ch = e.KeyChar;
if (!Char.IsDigit(ch)&& ch!= 8 & ;&(e.KeyChar!= ' - '))
{
e.Handled = true ;
}
}

私有 void txtZip_KeyPress( object sender,KeyPressEventArgs e)
{
char ch = e.KeyChar;
if (!Char.IsDigit(ch)&& ch!= 8
{
e.Handled = true ;
}
}

私有 void txtID_KeyPress( object sender,KeyPressEventArgs e)
{
char ch = e.KeyChar;
if (!Char.IsDigit(ch)&& ch!= 8
{
e.Handled = true ;
}
}
}
}

解决方案

);
if (txtEmail.Text.Length > 0
{
if (!rEMail.IsMatch(txtEmail.Text))
{
MessageBox.Show( 需要电子邮件 错误,MessageBoxButtons.OK,MessageBoxIcon.Error);
txtEmail.SelectAll();
e .Cancel = true ;
}
}
}

private void txtPhone_Validating( object sen der,CancelEventArgs e)
{
System.Text.RegularExpressions.Regex rPhone = new System.Text.RegularExpressions.Regex( @ (\ + \d {1,2} \s)?\(?\d {3} \\ \\)[\s .-] \d {3} [\s .-] \d {4}

)????;
if (txtPhone.Text.Length > 0
{
if (!rPhone.IsMatch(txtPhone.Text))
{
MessageBox.Show( 需要有效的电话号码 错误,MessageBoxButtons.OK,MessageBoxIcon.Error);
txtPhone.SelectAll();
e.Cancel = true ;
}
}
}

private void txtZip_Validating( object sender,CancelEventArgs e)
{
System.Text.RegularExpressions.Regex rZip = new System.Text.RegularExpressions.Regex( @ (^ \d {5} (-\d {4})?


)|(^ [ABCEGHJKLMNPRSTVXYabceghjklmnprstvxy] {1} \d {1} [ABCEGHJKLMNPRSTVWXYZabceghjklmnprstv xy] {1} * \d { 1} [ABCEGHJKLMNPRSTVWXYZabceghjklmnprstvxy] {1} \d {1}

If I click the header of my datagridview, it crashes. I have no idea how to fix it. I am getting this error:

An unhandled exception of type System.ArgumentOutOfRangeException occurred in mscorlib.dll

Additional information: Index was out of range. Must be non-negative and less than the size of the collection.

It's crashing at this point:

private void dgvProfiles_CellClick(object sender, DataGridViewCellEventArgs e)
        {   indexRow = e.RowIndex; // get the selected Row Index
            DataGridViewRow row = dgvProfiles.Rows[indexRow];
        }



What I have tried:

I have tried to edit DataGridViewRow row = dgvProfiles.Rows[indexRow], but nothing seems to work.

namespace ProfileManager
{
    public partial class Form1 : Form

    {
        DataTable dt = new DataTable();
        private int indexRow;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            dt.Columns.AddRange(new DataColumn[8]
            {new DataColumn("ID", typeof(string)),
                new DataColumn("First Name", typeof(string)),
            new DataColumn("Last Name", typeof(string)),
           new DataColumn ("Phone", typeof(string)),
           new DataColumn("Email", typeof(string)),
           new DataColumn("City", typeof(string)),
           new DataColumn("State", typeof(string)),
           new DataColumn("Zip", typeof(string))});

        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(txtID.Text))
            {
                MessageBox.Show("Please complete ID Name field.");
            }

            else if
                (String.IsNullOrEmpty(txtFirstName.Text))
            {
                MessageBox.Show("Please complete First Name field.");
            }

            else if (String.IsNullOrEmpty(txtLastName.Text))
            {
                MessageBox.Show("Please complete Last Name field.");
            }


            else if (String.IsNullOrEmpty(txtPhone.Text))
            {
                MessageBox.Show("Please complete Phone field.");
            }

            else if (String.IsNullOrEmpty(txtEmail.Text))
            {
                MessageBox.Show("Please complete Email field.");
            }

            else if (String.IsNullOrEmpty(txtCity.Text))
            {
                MessageBox.Show("Please complete City field.");
            }
            else if (String.IsNullOrEmpty(cbxState.Text))
            {
                MessageBox.Show("Please complete State field.");
            }
            else if (String.IsNullOrEmpty(txtZip.Text))
            {
                MessageBox.Show("Please complete Zip Code field.");
            }

            else {
                for (int row = 0; row < dgvProfiles.Rows.Count; row++)
                {
                    for (int col = 0; col < dgvProfiles.Columns.Count; col++)
                    {
                        if (dgvProfiles.Rows[row].Cells[col].Value != null &&
                          dgvProfiles.Rows[row].Cells[col].Value.Equals(txtEmail.Text.Trim()))
                        {
                            MessageBox.Show("Duplicate email was entered.");
                            return;
                        }

                        else if (dgvProfiles.Rows[row].Cells[col].Value != null &&
                          dgvProfiles.Rows[row].Cells[col].Value.Equals(txtID.Text.Trim()))
                        {
                            MessageBox.Show("Duplicate ID was entered.");
                            return;

                        }
                    }
                }

                dt.Rows.Add(txtID.Text, txtFirstName.Text, txtLastName.Text, txtPhone.Text, txtEmail.Text, txtCity.Text, cbxState.Text, txtZip.Text);
                this.dgvProfiles.DataSource = dt;
                txtID.Text = "";
                txtFirstName.Text = "";
                txtLastName.Text = "";
                txtPhone.Text = "";
                txtEmail.Text = "";
                txtPhone.Text = "";
                txtCity.Text = "";
                cbxState.SelectedIndex = -1;
                txtZip.Text = "";
                MessageBox.Show("Record was added successfully.");
            }

            

        }


        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            DialogResult dialog = MessageBox.Show("Are you sure you want to clear every field? All data will be lost!", "Clear", MessageBoxButtons.YesNo);
            if (dialog == DialogResult.Yes)
            {
                txtID.Text = "";
                txtFirstName.Text = "";
                txtLastName.Text = "";
                txtPhone.Text = "";
                txtEmail.Text = "";
                txtCity.Text = "";
                cbxState.SelectedIndex = -1;
                txtZip.Text = "";
                dt.Rows.Clear();
            }

            else {
                return;
            }

        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            DialogResult dialog = MessageBox.Show("Are you sure you want to close? All data will be lost!", "Exit", MessageBoxButtons.YesNo);
            if (dialog == DialogResult.Yes)
            {
                Application.Exit();
            }

            else
            {
                return;
            }
        }


        private void txtFirstName_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !(char.IsLetter(e.KeyChar) || e.KeyChar == (char)Keys.Back);
        }

        private void txtLastName_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !(char.IsLetter(e.KeyChar) || e.KeyChar == (char)Keys.Back);
        }

        private void txtCity_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !(char.IsLetter(e.KeyChar) || e.KeyChar == (char)Keys.Back);
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dgvProfiles.SelectedCells.Count <= 0)
            {
                MessageBox.Show("Please select a record you would like to delete.");
            }


            else {
                foreach (DataGridViewCell oneCell in dgvProfiles.SelectedCells)
                {
                    if (oneCell.Selected)
                    {
                        dgvProfiles.Rows.RemoveAt(oneCell.RowIndex);
                        MessageBox.Show("Record was deleted successfully!");
                        break;
                    }

                    else if (oneCell.RowIndex <= 0)
                    {
                        MessageBox.Show("Please select a record you would like to delete");
                    }
                }
                
            }

        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (dgvProfiles.SelectedCells.Count <= 0)
            {
                MessageBox.Show("No record was selected to update.");
            }

            else {
                for (int row = 0; row < dgvProfiles.Rows.Count; row++)
                {
                    for (int col = 0; col < dgvProfiles.Columns.Count; col++)
                    {
                        if (dgvProfiles.Rows[row].Cells[col].Value != null &&
                          dgvProfiles.Rows[row].Cells[col].Value.Equals(txtEmail.Text.Trim()))
                        {
                            MessageBox.Show("Duplicate email was entered.");
                            return;
                        }

                        else if (dgvProfiles.Rows[row].Cells[col].Value != null &&
                          dgvProfiles.Rows[row].Cells[col].Value.Equals(txtID.Text.Trim()))
                        {
                            MessageBox.Show("Duplicate ID was entered.");
                            return;

                        }
                    }
                }
                DataGridViewRow newDataRow = dgvProfiles.Rows[indexRow];
                newDataRow.Cells[0].Value = txtID.Text;
                newDataRow.Cells[1].Value = txtFirstName.Text;
                newDataRow.Cells[2].Value = txtLastName.Text;
                newDataRow.Cells[3].Value = txtPhone.Text;
                newDataRow.Cells[4].Value = txtEmail.Text;
                newDataRow.Cells[5].Value = txtCity.Text;
                newDataRow.Cells[6].Value = cbxState.Text;
                newDataRow.Cells[7].Value = txtZip.Text;

            }
        }

        private void dgvProfiles_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            indexRow = e.RowIndex; // get the selected Row Index
            DataGridViewRow row = dgvProfiles.Rows[indexRow];

            txtID.Text = row.Cells[0].Value.ToString();
            txtFirstName.Text = row.Cells[1].Value.ToString();
            txtLastName.Text = row.Cells[2].Value.ToString();
            txtPhone.Text = row.Cells[3].Value.ToString();
            txtEmail.Text = row.Cells[4].Value.ToString();
            txtCity.Text = row.Cells[5].Value.ToString();
            cbxState.Text = row.Cells[6].Value.ToString();
            txtZip.Text = row.Cells[7].Value.ToString();

        }

        private void txtEmail_Validating(object sender, CancelEventArgs e)
        {
            System.Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex(@"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");
            if (txtEmail.Text.Length > 0)
            {
                if (!rEMail.IsMatch(txtEmail.Text))
                {
                    MessageBox.Show("Email is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtEmail.SelectAll();
                    e.Cancel = true;
                }
            }
        }

        private void txtPhone_Validating(object sender, CancelEventArgs e)
        {
            System.Text.RegularExpressions.Regex rPhone = new System.Text.RegularExpressions.Regex(@"(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$");
            if (txtPhone.Text.Length > 0)
            {
                if (!rPhone.IsMatch(txtPhone.Text))
                {
                    MessageBox.Show("Valid phone number is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtPhone.SelectAll();
                    e.Cancel = true;
                }
            }
        }

        private void txtZip_Validating(object sender, CancelEventArgs e)
        {
            System.Text.RegularExpressions.Regex rZip = new System.Text.RegularExpressions.Regex(@"(^\d{5}(-\d{4})?$)|(^[ABCEGHJKLMNPRSTVXYabceghjklmnprstvxy]{1}\d{1}[ABCEGHJKLMNPRSTVWXYZabceghjklmnprstv‌​xy]{1} *\d{1}[ABCEGHJKLMNPRSTVWXYZabceghjklmnprstvxy]{1}\d{1}$)");
            if (txtZip.Text.Length > 0)
            {
                if (!rZip.IsMatch(txtZip.Text))
                {
                    MessageBox.Show("Valid zip is required. Must be in a 5 digit format.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtZip.SelectAll();
                    e.Cancel = true;
                }
            }

        }

        private void txtPhone_KeyPress(object sender, KeyPressEventArgs e)
        {
            char ch = e.KeyChar;
            if (!Char.IsDigit(ch) && ch != 8 && (e.KeyChar != '-'))
            {
                e.Handled = true;
            }
        }

        private void txtZip_KeyPress(object sender, KeyPressEventArgs e)
        {
            char ch = e.KeyChar;
            if (!Char.IsDigit(ch) && ch != 8)
            {
                e.Handled = true;
            }
        }

        private void txtID_KeyPress(object sender, KeyPressEventArgs e)
        {
            char ch = e.KeyChar;
            if (!Char.IsDigit(ch) && ch != 8)
            {
                e.Handled = true;
            }
        }
    }
}

解决方案

"); if (txtEmail.Text.Length > 0) { if (!rEMail.IsMatch(txtEmail.Text)) { MessageBox.Show("Email is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtEmail.SelectAll(); e.Cancel = true; } } } private void txtPhone_Validating(object sender, CancelEventArgs e) { System.Text.RegularExpressions.Regex rPhone = new System.Text.RegularExpressions.Regex(@"(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}


"); if (txtPhone.Text.Length > 0) { if (!rPhone.IsMatch(txtPhone.Text)) { MessageBox.Show("Valid phone number is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPhone.SelectAll(); e.Cancel = true; } } } private void txtZip_Validating(object sender, CancelEventArgs e) { System.Text.RegularExpressions.Regex rZip = new System.Text.RegularExpressions.Regex(@"(^\d{5}(-\d{4})?


)|(^[ABCEGHJKLMNPRSTVXYabceghjklmnprstvxy]{1}\d{1}[ABCEGHJKLMNPRSTVWXYZabceghjklmnprstv‌​xy]{1} *\d{1}[ABCEGHJKLMNPRSTVWXYZabceghjklmnprstvxy]{1}\d{1}


这篇关于单击标题时,Datagridview崩溃。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆