This is a migrated thread and some comments may be shown as answers.

[Solved] Issue with InsertCommand and creating new row

2 Answers 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
C O
Top achievements
Rank 1
C O asked on 28 Jan 2010, 11:17 PM
I created a sub to create the new row from the edit form, however, the error "conversion type from dbnull to type boolean is not valid" pops up instead of the form.  I though it to be a null input to the checkbox, which I have 4 on the form.  But even forcing a 'true' value does not work.  Can anyone find my error?

Protected

 

Sub RadGrid1_InsertCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.InsertCommand

 

 

Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)

 

 

Dim userControl As UserControl = CType(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), UserControl)

 

 

 

 

Dim newRow As DataRow = Me.Ntable.NewRow

 

 

 

 

Dim newValues As Hashtable = New Hashtable

 

newValues(

"N") = CType(userControl.FindControl("NTextBox"), RadTextBox).Text

 

newValues(

"DNumber") = CType(userControl.FindControl("PNUMBER"), RadTextBox).Text.Take(13)

 

newValues(

"PNUMBER") = CType(userControl.FindControl("PNUMBER"), RadTextBox).Text

 

newValues(

"Title") = CType(userControl.FindControl("Title"), RadTextBox).Text

 

newValues(

"worder") = 0

 

newValues(

"SMRB") = CType(userControl.FindControl("SMRB"), RadTextBox).Text

 

newValues(

"SCAR") = CType(userControl.FindControl("SCAR"), RadTextBox).Text

 

newValues(

"Dposition") = CType(userControl.FindControl("Dposition"), RadTextBox).Text

 

newValues(

"LItems") = CType(userControl.FindControl("LItems"), RadTextBox).Text

 

newValues(

"QTY") = CType(userControl.FindControl("QTY"), RadTextBox).Text

 

newValues(

"AffectedA") = CType(userControl.FindControl("AffectedA"), RadTextBox).Text

 

newValues(

"Slier") = CType(userControl.FindControl("Slier"), RadTextBox).Text

 

newValues(

"Parer") = CType(userControl.FindControl("Parer"), RadTextBox).Text

 

newValues(

"QApp") = CType(userControl.FindControl("QApp"), RadTextBox).Text

 

newValues(

"Eer") = CType(userControl.FindControl("Eer"), RadTextBox).Text

 

newValues(

"Lon") = CType(userControl.FindControl("Lon"), RadTextBox).Text

 

newValues(

"Stus") = CType(userControl.FindControl("Stus"), RadTextBox).Text

 

newValues(

"Dancy") = CType(userControl.FindControl("Dancy"), RadTextBox).Text

 

newValues(

"cause") = 0

 

newValues(

"CAction") = CType(userControl.FindControl("CAction"), RadTextBox).Text

 

newValues(

"Subtion") = CType(userControl.FindControl("Subtion"), RadTextBox).Text

 

newValues(

"actiondate") = Date.Now

 

newValues(

"compsn") = CType(userControl.FindControl("compsn"), RadTextBox).Text

 

newValues(

"drcode") = 0

 

newValues(

"reworkordno") = CType(userControl.FindControl("reworkordno"), RadTextBox).Text

 

newValues(

"corractionreqyes") = CType(userControl.FindControl("corractionreqyes"), CheckBox).Checked

 

newValues(

"corractionreqno") = CType(userControl.FindControl("corractionreqno"), CheckBox).Checked

 

newValues(

"purchsig") = CType(userControl.FindControl("purchsig"), RadTextBox).Text

 

newValues(

"shipperno") = CType(userControl.FindControl("shipperno"), RadTextBox).Text

 

newValues(

"shop1") = CType(userControl.FindControl("shop1"), RadTextBox).Text

 

newValues(

"qainsp1") = CType(userControl.FindControl("qainsp1"), RadTextBox).Text

 

newValues(

"shop2") = CType(userControl.FindControl("shop2"), RadTextBox).Text

 

newValues(

"rqainsp2") = CType(userControl.FindControl("qainsp2"), RadTextBox).Text

 

newValues(

"reworkinst") = CType(userControl.FindControl("reworkinst"), RadTextBox).Text

 

newValues(

"min") = CType(userControl.FindControl("min"), CheckBox).Checked

 

newValues(

"maj") = CType(userControl.FindControl("maj"), CheckBox).Checked

 

 

 

newValues(

"N_ID") = (CType(Me.Ntable.Rows((Me.Ntable.Rows.Count - 1))("N_ID"), Integer) + 1001)

 

 

Try

 

 

For Each entry As DictionaryEntry In newValues

 

newRow(

CType(entry.Key, String)) = entry.Value

 

 

Next

 

 

Me.Ntable.Rows.Add(newRow)

 

 

Me.Ntable.AcceptChanges()

 

 

Catch ex As Exception

 

 

Dim lblError As Label = New Label()

 

lblError.Text =

"Unable to insert N. Reason: " + ex.Message

 

lblError.ForeColor = System.Drawing.Color.Red

RadGrid1.Controls.Add(lblError)

e.Canceled =

True

 

 

End Try

 

 

End Sub

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 29 Jan 2010, 11:53 AM
Hi,

Can you try setting a default value to the checkbox in the Insert form and then see if the error still occurs.Here is how you can achieve the same.

Thanks,
Princy
0
C O
Top achievements
Rank 1
answered on 29 Jan 2010, 04:25 PM
thanks for pointing me to the link.  I added the following code to my itemcommand sub and it works now.

If (e.CommandName = RadGrid.InitInsertCommandName) Then
e.Canceled = True
'Prepare an IDictionary with the predefined values
Dim newValues As System.Collections.Specialized.ListDictionary = New System.Collections.Specialized.ListDictionary()

'set initial checked state for the checkbox on init insert
newValues("maj") = False
newValues("min") = False
newValues("corractionreqyes") = False
newValues("corractionreqno") = False

'Insert the item and rebind
e.Item.OwnerTableView.InsertItem(newValues)
End If

 

 

Tags
Grid
Asked by
C O
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
C O
Top achievements
Rank 1
Share this question
or