Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Friday, 14 October 2011

DevExpress, GridControl, how the Best Fit Column feature works

The property GridView.BestFitMaxRowCount indicates how many rows will be processed in order to adjust the best column width.
  • -1 means that all row will be processed
  • 0 nothing
  • Any other value indicates how many will be processed
For performance issues apply a small number or apply 0.
Important note: If auto width is enabled, a column's GridColumn.Width property doesn't contain its visible width, but the value used when auto width is false, so that a column's layout can be restored. A column's visible width is available via its GridColumn.VisibleWidth property.

Monday, 10 October 2011

Method code, to convert a deleted DataRow to non deleted DataRow

        /// <summary>
        /// Get the deleted record you provide as non deleted row; NOTE: the State of the row is ADDED.
        /// </summary>
        /// <param name="sourceDataTable"></param>
        /// <param name="deletedDataRow"></param>
        /// <returns></returns>
        public static DataRow readDeletedDataRow(DataTable sourceDataTable,DataRow deletedDataRow) {
            int deletedDataRowIndex = sourceDataTable.Rows.IndexOf(deletedDataRow);
            DataView deletedView = new DataView(sourceDataTable, null, null, DataViewRowState.Deleted);
            DataTable deletedRecordsTable = deletedView.ToTable();
            return deletedRecordsTable.Rows[deletedDataRowIndex];
        }

Accessing deleted row field values from data table with C#.net

Solution #1



          Sometimes we delete data row in data table of dataset. Then we may need again to get deleted row field information from the dataset back for some calculation purpose. It gives error if we want to access the row data from the data table telling "The data row has been deleted ...".

         We can still access the field data information by using DataRowVersion.Original parameter. For example

         int customerId = Convert.ToInt32( DataTable1.Rows[0][0, DataRowVersion.Original];

         This will give the original version of the row data. And voila - we have our original data back.


Solution #2



          We can make a Data View out of the datatable. Then convert that data view into data table again. This will give us the original data. But this time the datarowstate = "added".

          We see one example code for this.

          DataView myView = new DataView(sourceTable, null, null, DataViewRowState.Deleted);
          DataTable myTable = myView.ToTable();