سلام بر برنامه نویسان عزیز با یه کد سی شارپ دیگه در خدمتتون هستم.امیدوارم که از این استفاده کافی رو ببرید.
private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up)
{
if (grid.RowCount != 0)
{
if (grid.CurrentRow != null)
{
if (grid.CurrentRow.Index > 0)
{
grid.CurrentCell = grid[0, grid.CurrentRow.Index - 1];
}
}
}
}
else if (e.KeyCode == Keys.Down)
{
if (grid.RowCount != 0)
{
if (grid.CurrentRow != null)
{
if (grid.CurrentRow.Index < grid.RowCount)
{
grid.CurrentCell = grid[0, grid.CurrentRow.Index + 1];
}
}
}
}
}
{
if (e.KeyCode == Keys.Up)
{
if (grid.RowCount != 0)
{
if (grid.CurrentRow != null)
{
if (grid.CurrentRow.Index > 0)
{
grid.CurrentCell = grid[0, grid.CurrentRow.Index - 1];
}
}
}
}
else if (e.KeyCode == Keys.Down)
{
if (grid.RowCount != 0)
{
if (grid.CurrentRow != null)
{
if (grid.CurrentRow.Index < grid.RowCount)
{
grid.CurrentCell = grid[0, grid.CurrentRow.Index + 1];
}
}
}
}
}
برای اطلاعات بیشتر درباره ی e.KeyCode این لینک و این لینک و این لینک را مشاهده کنید.
برای اطلاعات بیشتر درباره ی grid view CurrentRow.Index این لینک و این لینک و این لینک را مشاهده کنید.
برای اطلاعات بیشتر درباره ی grid view RowCount این لینک و این لینک و این لینک را مشاهده کنید.
برای اطلاعات بیشتر درباره ی grid view CurrentCell این لینک و این لینک و این لینک را مشاهده کنید.
اگر کد بالا کار نکرد ، این کد را امتحان کنید:
using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace SearchRecord
{
public partial class frmSearch : Form
{
//Connection String
string cs = "Data Source=.;Initial Catalog=Sample;Integrated Security=true;";
SqlConnection con;
SqlDataAdapter adapt;
DataTable dt;
public frmSearch()
{
InitializeComponent();
}
//frmSearch Load Event
private void frmSearch_Load(object sender, EventArgs e)
{
con = new SqlConnection(cs);
con.Open();
adapt = new SqlDataAdapter("select * from tbl_Employee",con);
dt = new DataTable();
adapt.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
}
//txt_SearchName TextChanged Event
private void txt_SearchName_TextChanged(object sender, EventArgs e)
{
con = new SqlConnection(cs);
con.Open();
adapt = new SqlDataAdapter("select * from tbl_Employee where FirstName like '"+txt_SearchName.Text+"%'", con);
dt = new DataTable();
adapt.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
}
}
}
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace SearchRecord
{
public partial class frmSearch : Form
{
//Connection String
string cs = "Data Source=.;Initial Catalog=Sample;Integrated Security=true;";
SqlConnection con;
SqlDataAdapter adapt;
DataTable dt;
public frmSearch()
{
InitializeComponent();
}
//frmSearch Load Event
private void frmSearch_Load(object sender, EventArgs e)
{
con = new SqlConnection(cs);
con.Open();
adapt = new SqlDataAdapter("select * from tbl_Employee",con);
dt = new DataTable();
adapt.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
}
//txt_SearchName TextChanged Event
private void txt_SearchName_TextChanged(object sender, EventArgs e)
{
con = new SqlConnection(cs);
con.Open();
adapt = new SqlDataAdapter("select * from tbl_Employee where FirstName like '"+txt_SearchName.Text+"%'", con);
dt = new DataTable();
adapt.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
}
}
}
یک 2 نظر
علی انصاری پور
سلام مطلب رو ویرایش کردم و یک کد دیگه اضافه کردم.
novinsupport
این کد توی down یه ایراد داره .