We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Adding a default value to newly inserted row

What''s the best way to insert a default value when a user begins a new, blank row in a databound grid? Right now I''ve tried the following: Me.GridBoundColumn23.MappingName = "QAID" Me.GridBoundColumn23.ReadOnly = True Me.GridBoundColumn23.StyleInfo.CellValueType = GetType(System.Int32) Me.GridBoundColumn23.StyleInfo.CellValue = qaID This inserts the value, but as soon as any cell within the row is selected, the value disappears. What''s wrong? Thanks!

4 Replies

AD Administrator Syncfusion Team April 21, 2005 06:16 AM UTC

Hi Helmut I''m using the GridDataBoundGrid.Binder.EditModeChanged event to handle this. Here an example: private void Binder_EditModeChanged(object sender, EventArgs e) { if (this.gridData.Binder.IsEditing && this.gridData.Binder.IsAddNew ) { CurrencyManager cm = this.gridData.Binder.BindingContext[this.DataSource, this.DataMember] as CurrencyManager; if( cm.Position != -1 ) { DataRow addedRow = ((DataRowView)cm.Current).Row; if( addedRow.RowState == DataRowState.Detached ) { // add the default values } } } } Regards, Thomas >What''s the best way to insert a default value when a user begins a new, blank row in a databound grid? Right now I''ve tried the following: > >Me.GridBoundColumn23.MappingName = "QAID" >Me.GridBoundColumn23.ReadOnly = True > Me.GridBoundColumn23.StyleInfo.CellValueType = GetType(System.Int32) > Me.GridBoundColumn23.StyleInfo.CellValue = qaID > >This inserts the value, but as soon as any cell within the row is selected, the value disappears. What''s wrong? Thanks! > >


HE Helmut April 21, 2005 02:58 PM UTC

Thank you! It looks like it works, the only problem is that I need a VB.NET translation. When I reference my GDBG named DataGrid1, I don''t see a Binder reference available to choose. Anyone care to help? Helmut >Hi Helmut > >I''m using the GridDataBoundGrid.Binder.EditModeChanged event to handle this. > >Here an example: > private void Binder_EditModeChanged(object sender, EventArgs e) > { > if (this.gridData.Binder.IsEditing && this.gridData.Binder.IsAddNew ) > { > CurrencyManager cm = this.gridData.Binder.BindingContext[this.DataSource, this.DataMember] as CurrencyManager; > if( cm.Position != -1 ) > { > DataRow addedRow = ((DataRowView)cm.Current).Row; > if( addedRow.RowState == DataRowState.Detached ) > { > // add the default values > } > } > } > } > >Regards, >Thomas > >>What''s the best way to insert a default value when a user begins a new, blank row in a databound grid? Right now I''ve tried the following: >> >>Me.GridBoundColumn23.MappingName = "QAID" >>Me.GridBoundColumn23.ReadOnly = True >> Me.GridBoundColumn23.StyleInfo.CellValueType = GetType(System.Int32) >> Me.GridBoundColumn23.StyleInfo.CellValue = qaID >> >>This inserts the value, but as soon as any cell within the row is selected, the value disappears. What''s wrong? Thanks! >> >>


HE Helmut April 21, 2005 03:30 PM UTC

I''ve tried to take a shot at it, but I know that the part after "Handles" isn''t correct. Can someone tell me what I''m doing wrong? If there is anything else that looks goofy, don''t hesitate to comment. Thanks again! Private Sub DataGrid1_Binder_EditModeChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.Binder.EditModeChanged If (Me.DataGrid1.Binder.IsEditing And Me.DataGrid1.Binder.IsAddNew) Then cm = Me.DataGrid1.Binder.BindingContext(Me.DataGrid1.DataSource, Me.DataGrid1.DataMember) If cm.Position <> -1 Then addedRow = CType(cm.Current, DataRowView).Row If addedRow.RowState = DataRowState.Detached Then addedRow("QAID") = qaID End If End If End If End Sub >Thank you! It looks like it works, the only problem is that I need a VB.NET translation. When I reference my GDBG named DataGrid1, I don''t see a Binder reference available to choose. Anyone care to help? > >Helmut > >>Hi Helmut >> >>I''m using the GridDataBoundGrid.Binder.EditModeChanged event to handle this. >> >>Here an example: >> private void Binder_EditModeChanged(object sender, EventArgs e) >> { >> if (this.gridData.Binder.IsEditing && this.gridData.Binder.IsAddNew ) >> { >> CurrencyManager cm = this.gridData.Binder.BindingContext[this.DataSource, this.DataMember] as CurrencyManager; >> if( cm.Position != -1 ) >> { >> DataRow addedRow = ((DataRowView)cm.Current).Row; >> if( addedRow.RowState == DataRowState.Detached ) >> { >> // add the default values >> } >> } >> } >> } >> >>Regards, >>Thomas >> >>>What''s the best way to insert a default value when a user begins a new, blank row in a databound grid? Right now I''ve tried the following: >>> >>>Me.GridBoundColumn23.MappingName = "QAID" >>>Me.GridBoundColumn23.ReadOnly = True >>> Me.GridBoundColumn23.StyleInfo.CellValueType = GetType(System.Int32) >>> Me.GridBoundColumn23.StyleInfo.CellValue = qaID >>> >>>This inserts the value, but as soon as any cell within the row is selected, the value disappears. What''s wrong? Thanks! >>> >>>


AD Administrator Syncfusion Team April 21, 2005 03:43 PM UTC

Do not use a Handles clause. Instead remove that cluase from the sub''s definition and in Form.Load, use Addhandler to subscribe to the event. Addhandler DataGrid1.Binder.EditModeChanged, addressof DataGrid1_Binder_EditModeChanged

Loader.
Live Chat Icon For mobile
Up arrow icon