[ L a d y @ 12.02.2007. 07:08 ] @
DataGridView se koristi za promene podataka u tabeli, dodavanje redova je onemoguceno. Sta treba dodati kodu da bi se prosledila promena ako postoji samo 1 red u tabeli, posto tada ne moze da odreaguje na PositionChanged dogadjaj? //tracks for PositionChanged event last row private DataRow LastDataRow = null; /// <SUMMARY> /// Checks if there is a row with changes and /// writes it to the database /// </SUMMARY> private void UpdateRowToDatabase() { if (LastDataRow != null) { if (LastDataRow.RowState == DataRowState.Modified) { // this.ordersTableAdapter.Fill(this.baseDataSet.Orders); ordersTableAdapter.Update(LastDataRow); } } } private void ordersBindingSource_PositionChanged(object sender, EventArgs e) { try { // if the user moves to a new row, check if the // last row was changed theBindingSource = (BindingSource)sender; ThisDataRow = ((DataRowView)theBindingSource.Current).Row; if (ThisDataRow == LastDataRow) { // we need to avoid to write a datarow to the // database when it is still processed. Otherwise // we get a problem with the event handling of //the DataTable. throw new ApplicationException("It seems the" + " PositionChanged event was fired twice for" + " the same row"); } UpdateRowToDatabase(); // track the current row for next // PositionChanged event LastDataRow = ThisDataRow; } catch { } } |