using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
DataTable table;
DataTable table1;
public Form1()
{
InitializeComponent();
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
var item = dataGridView1.Rows[e.RowIndex].Cells[1].Value;
table1.Rows.Add(item.ToString());
}
private void Form1_Load(object sender, EventArgs e)
{
table = new DataTable();
table.Columns.Add("Id", typeof(int));
table.Columns.Add("Name", typeof(string));
table.Rows.Add(1,"Mee");
table.Rows.Add(2, "Yha");
dataGridView1.DataSource = table;
table1 = new DataTable();
table1.Columns.Add("Name", typeof(string));
dataGridView2.DataSource = table1;
}
private void button1_Click(object sender, EventArgs e)
{
int rowIndex = dataGridView2.CurrentCell.RowIndex;
dataGridView2.Rows.RemoveAt(rowIndex);
}
private void dataGridView2_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyData == Keys.Delete)
{
int rowIndex = dataGridView2.CurrentCell.RowIndex;
dataGridView2.Rows.RemoveAt(rowIndex);
}
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar == (char)13)
{
DataView dv = table.DefaultView;
dv.RowFilter = string.Format("Name like '%{0}%'" , textBox1.Text);
dataGridView1.DataSource = dv.ToTable();
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
DataView dv = table.DefaultView;
dv.RowFilter = string.Format("Name like '%{0}%'", textBox1.Text);
dataGridView1.DataSource = dv.ToTable();
}
}
}