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.
Unfortunately, activation email could not send to your email. Please try again.

Adding a default value to newly inserted row

Thread ID:

Created:

Updated:

Platform:

Replies:

27979 Apr 21,2005 01:02 AM Apr 21,2005 11:43 AM Windows Forms 4
loading
Tags: GridControl
Helmut
Asked On April 21, 2005 01:02 AM

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!

Administrator [Syncfusion]
Replied On April 21, 2005 02:16 AM

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! > >

Helmut
Replied On April 21, 2005 10:58 AM

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! >> >>

Helmut
Replied On April 21, 2005 11:30 AM

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! >>> >>>

Administrator [Syncfusion]
Replied On April 21, 2005 11:43 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;