public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Users us = new Users();
private void Form1_Load(object sender, EventArgs e)
{
Users uss = new Users();
User u = new User();
u.name = "aaa";
u.pwd = "111";
uss.Add(u);
u = new User();
u.name = "bbb";
u.pwd = "222";
uss.Add(u);
u = new User();
u.name = "ccc";
u.pwd = "333";
uss.Add(u);
dataGridView1.DataSource = uss;
}
private void button1_Click(object sender, EventArgs e)
{
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
User u = new User();
u.name = dataGridView1.SelectedRows[0].Cells["name"].Value.ToString();
u.pwd = dataGridView1.SelectedRows[0].Cells["pwd"].Value.ToString();
if (us.Count != 0)
{
foreach (User uu in us)
{
if (u.name == uu.name)
{
MessageBox.Show("已经添加!");
return;
}
}
us.Add(u);
dataGridView2.DataSource = us;
dataGridView2.DataSource = null;
dataGridView2.DataSource = us;
}
else
{
//dataGridView2.DataSource = null;
us.Add(u);
dataGridView2.DataSource = us;
}
}
}
class User
{
private string m_Name;
public string name
{
get { return m_Name; }
set { m_Name = value; }
}
private string m_Pwd;
public string pwd
{
get { return m_Pwd; }
set { m_Pwd = value; }
}
}
class Users :List<User>
{
}
{
public Form1()
{
InitializeComponent();
}
Users us = new Users();
private void Form1_Load(object sender, EventArgs e)
{
Users uss = new Users();
User u = new User();
u.name = "aaa";
u.pwd = "111";
uss.Add(u);
u = new User();
u.name = "bbb";
u.pwd = "222";
uss.Add(u);
u = new User();
u.name = "ccc";
u.pwd = "333";
uss.Add(u);
dataGridView1.DataSource = uss;
}
private void button1_Click(object sender, EventArgs e)
{
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
User u = new User();
u.name = dataGridView1.SelectedRows[0].Cells["name"].Value.ToString();
u.pwd = dataGridView1.SelectedRows[0].Cells["pwd"].Value.ToString();
if (us.Count != 0)
{
foreach (User uu in us)
{
if (u.name == uu.name)
{
MessageBox.Show("已经添加!");
return;
}
}
us.Add(u);
dataGridView2.DataSource = us;
dataGridView2.DataSource = null;
dataGridView2.DataSource = us;
}
else
{
//dataGridView2.DataSource = null;
us.Add(u);
dataGridView2.DataSource = us;
}
}
}
class User
{
private string m_Name;
public string name
{
get { return m_Name; }
set { m_Name = value; }
}
private string m_Pwd;
public string pwd
{
get { return m_Pwd; }
set { m_Pwd = value; }
}
}
class Users :List<User>
{
}
仁者乐膳,智者乐睡。我都爱~