I follows a DataGridView with data source:
bindingSource = DataTable dataGridView.DataSource = bindingSource editing cells or add new rows I apply a different formatting style, if I lose DataGridView click Sort header formatting style on one of the columns So my question is:
After sorting the datagridware, how do I know which cell I have been added or added?, Then I can apply the formatting style again.
VB.NET or C # is OK
I changed Selvol the string / Bdlunga event, sample:
private sub DataGridView_CellValueChanged (as System.Object in, manages) DataGridView.CellValueChanged e DataGridViewCellEventArgs e.RowIndex = -1 or IsNothing (DataGridView.CurrentCell) then return end so as dim cellPosition Short = DataGridView.CurrentCell.ColumnIndex dim styles (25) String dim styles as Cell = DataGridView.Rows (e.RowIndex) .cs ("CellStyleDescriptor"). If not IsDBNull value (stylesCell) and _ IsNothing not (stylesCell) then Styles = Split (stylesCell, ",") End If IsDBNull (DataGridView.Rows (e.RowIndex) .Cells ( "ID"). Value) then integer as I to = 0 "25 is the new road added Styles (i) =" N "Next Otherwise Styles (cellPosition) = 'e' to edit / modify cell terminated DataGridView.Rows (e.RowIndex ) .cs ("CellStyleDescriptor"). Value = String.Join ( ",", String) closing sub Apply reading styles Selformeting events / sample:
private and b DataGridView_CellFormatting (this System.Object, manages) DataGridView.CellFormatting e DataGridViewCellFormattingEventArgs e.RowIndex = -1 or e.ColumnIndex = -1 comeback finally then dim styles (25) string styles = Split (DataGridViewkRows as (e.RowIndex) .Cells ( "CellStyleDescriptor"). select value, "") Case styles (EkColumnIndex) Case 'E' 'edited cell e.CellStyle.BackColor = modifiedStyle.BackColor e.CellStyle.ForeColor = modifiedStyle. ForeColor get episode "N" new cell e.CellStyle.BackColor = newStyle.BackColor e.CellStyle.ForeColor = newStyle.ForeColor End Select End Sub I hope it helps someone
No comments:
Post a Comment