DGV'yi aşağıdaki şekilde gösterdim. Metin kutusunun girişini aşağıdaki gibi DGV'ye eklemeye çalışıyorum.Metin Kutusu'na DGV'ye Satır Ekleme
Unbound DGV:
private void Form2_Load(object sender, EventArgs e)
{
DataGridViewColumn srno = new DataGridViewTextBoxColumn();
dataGridView1.Columns.Insert(0, srno);
DataGridViewColumn part = new DataGridViewTextBoxColumn();
dataGridView1.Columns.Insert(0, part);
DataGridViewColumn cts = new DataGridViewTextBoxColumn();
cts.ValueType = typeof(decimal);
dataGridView1.Columns.Insert(0, cts);
DataGridViewColumn rt =new DataGridViewTextBoxColumn();
rt.ValueType = typeof(decimal);
dataGridView1.Columns.Insert(0, rt);
DataGridViewColumn debit =new DataGridViewTextBoxColumn();
debit.ValueType = typeof(decimal);
dataGridView1.Columns.Insert(0, debit);
}
// textBox EventHandler
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if ((Keys)e.KeyChar == Keys.Enter)
{
int i = dataGridView1.CurrentCell.RowIndex;
dataGridView1[1, i].Value = textBox1.Text;
dataGridView1.Focus();
}
}
Bound DGV:
private void Form1_Load(object sender, EventArgs e)
{
string connstr = "server=.;initial catalog=maa;uid=mah;pwd=mah";
SqlConnection con = new SqlConnection(connstr);
con.Open();
DataSet mydatasett;
string dgv = " select srno,particulars,carats,rate,debit from depurchaseA";
SqlCommand dgvcmd = new SqlCommand(dgv, con);
SqlDataAdapter dgvdap = new SqlDataAdapter(dgvcmd);
mydatasett = new DataSet();
dgvdap.Fill(mydatasett);
bindingsource2 = new BindingSource();
bindingsource2.DataSource = mydatasett;
bindingsource2.DataMember = mydatasett.Tables[0].TableName;
dataGridView1.DataSource = bindingsource2;
}
**//And textbox Event handler :**
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if ((Keys)e.KeyChar == Keys.Enter)
{
int i = dataGridView1.CurrentCell.RowIndex;
dataGridView1[1, i].Value = textBox1.Text;
dataGridView1.Focus();
}
}
yukarıda bağlanmamış DGV'nin ama Bound DGV'nin aynı değil eserlerinden çalışıyor. TextBox girdisini Bound DGV'ye eklemek istiyorum. Basit bir yolu var mı?
Bu işe yaramıyor, yukarıda kullandığım gibi aynı şey farklı değil. – mahesh