و سوال دیگه ایم که چکار کنم که وقتی روی یک سلول در datagridview کلیک میکنم . محتوایات رکورد آن سلول در textbox ها قرار گیرد . خیلی ممنون.
//SqlConnection objConnection = new SqlConnection("Data Source=IRAN;Initial Catalog=MOJAVEZ;Integrated Security=True");
SqlDataAdapter objDataAdapter = newSqlDataAdapter();
DataSet objDataSet = newDataSet();
CurrencyManager objCurrencyManager;
DataView objDataView;
int @c_admin = int.Parse(this.grdAuthorTitles.CurrentRow.Cells[0].Value.ToString());
//SqlConnection objConnection = new SqlConnection("Data Source=IRAN;Initial Catalog=MOJAVEZ;Integrated Security=True");
objDataAdapter.SelectCommand = newSqlCommand();
objDataAdapter.SelectCommand.Connection = objConnection;
objDataAdapter.SelectCommand.CommandText = "SELECT * FROM s_admin ";
objDataAdapter.SelectCommand.CommandType = CommandType.Text;
// Open the database connection...
objConnection.Open();
// Fill the DataSet object with data...
objDataAdapter.Fill(objDataSet, "s_admin");
objDataView = newDataView(objDataSet.Tables["s_admin"]);
// textBox1.DataBindings.Add("Text", objDataView, "ac");
// textBox2.DataBindings.Add("Text", objDataView, "re");
objCurrencyManager = (CurrencyManager)(this.BindingContext[objDataView]);
objDataView.Sort = "c_admin";
int intPosition = objDataView.Find(@c_admin);
if (intPosition == -1)
{
// Display a message
// that the record was not found...
// ToolStripStatusLabel1.Text = "Record Not Found";
MessageBox.Show("رکورد مورد نظر پیدا نشد");
}
else
{
// Otherwise display a message that the record
// was found and reposition the CurrencyManager
// to that record...
//ToolStripStatusLabel1.Text = "Record Found";
// MessageBox.Show("record fond");
objCurrencyManager.Position = intPosition;
maskedTextBox1.DataBindings.Add("Text", objDataView, "c_admin"); ;
textBox2.DataBindings.Add("Text", objDataView, "n_admin");
textBox3.DataBindings.Add("Text", objDataView, "f_admin");
textBox4.DataBindings.Add("Text", objDataView, "p_admin");
maskedTextBox1.DataBindings.Clear();
textBox2.DataBindings.Clear();
textBox3.DataBindings.Clear();
textBox4.DataBindings.Clear();
}
objConnection.Close();
این کد تو برنامه ی من همون کاری را انجام میده که شما لازم دارین
با کمی تعقیر این کد میتونی ازش استفاده کنی