1. Пользуйтесь тегами кода. - [code] ... [/code] 2. Точно указывайте язык, название и версию компилятора (интерпретатора). 3. Название темы должно быть информативным. В описании темы указываем язык!!!
как сохранять измения в DataGridView? В новигаторе есть кнопка SAVE, но она сохраняет если в таблицу ТОЛЬКО дабавляются записи, а не изменяются. Если изменить и сохранить получается ошибка.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;
namespace WindowsFormsApplication6 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) { // TODO: данная строка кода позволяет загрузить данные в таблицу "mydbDataSet.mytable". При необходимости она может быть перемещена или удалена. this.mytableTableAdapter.Fill(this.mydbDataSet.mytable); // this.mytableDataGridView.AutoResizeColumns();
} public DataRow lastdatarow = null;
private void updateRowToDatabase() { if (lastdatarow != null) { if (lastdatarow.RowState == DataRowState.Modified) { mytableTableAdapter.Update(lastdatarow); } } }
private void mytableBindingSource_PositionChanged(object sender, EventArgs e) { BindingSource thisBindingSource = (BindingSource)sender; DataRow thisdatarow = ((DataRowView)thisBindingSource.Current).Row; if (thisdatarow == lastdatarow) { throw new ApplicationException("It seems the" + " PositionChanged event was fired twice for" + " the same row"); } updateRowToDatabase(); lastdatarow=thisdatarow; }