Click here to Skip to main content
15,923,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys ,
Am in Vb.net and I have a big Challenge any meaning assistance will be greatly appreciated.
I need help seriously, I am working with a hierarchical datagridview which is bound to a datatable(H_dt) which I created programmatically (Shown below).
Public Function FillTable(ByVal lngValue As Int32, ByVal Quantity As String, ByVal Description As String, ByVal cost As String, ByVal status As String) As Int32?
H_dr = H_dt.NewRow()
H_lngCounter += 1
H_dr("id") = H_lngCounter
H_dr("Quantity") = Quantity
H_dr("description") = Description
H_dr("Cost") = cost
H_dr("id_parent") = lngValue
H_dr("Status") = status
H_dt.Rows.Add(H_dr)

Return H_lngCounter
End Function
Public Sub FillTableDefinition()

' Create a DataColumn and set various properties.


Dim dc As New DataColumn

'as orderdetails id
dc = New DataColumn()
dc.DataType = System.Type.GetType("System.Int32")
dc.AllowDBNull = True
dc.ColumnName = "ID"
H_dt.Columns.Add(dc)

'As Quantity
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.AllowDBNull = True
dc.ColumnName = "Quantity"
dc.DefaultValue = DBNull.Value
H_dt.Columns.Add(dc)



'as item description
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.AllowDBNull = True
dc.ColumnName = "Description"
H_dt.Columns.Add(dc)

'as cost
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.AllowDBNull = True
dc.ColumnName = "Cost"
dc.DefaultValue = DBNull.Value
H_dt.Columns.Add(dc)

dc = New DataColumn
dc.DataType = System.Type.GetType("System.Int32")
dc.AllowDBNull = True
dc.ColumnName = "ID_Parent"
H_dt.Columns.Add(dc)

dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.AllowDBNull = True
dc.ColumnName = "Status"
H_dt.Columns.Add(dc)



End Sub

And consequently the grid is bound to the datatable.

FrmBooking.HDGVLaundry.DataSource = H_dt
End Sub

Now the thing is, I envisage a situation while the user is entering data in to the datagridview he decides to void the order or maybe commit the order, this implies that in either situation the booking form, where you have the datagrid on which you have those orders will be exited and when next the user calls up the form for a fresh or another order the datagrid will be cleared of the previous order and awaiting user entry for fresh orders or transaction. Now all this works fine up till a point.

(Please note that the orders are not entered manually but entered through the click event of buttons which are on the booking form as well each carrying the names of the product or items and their description and cost).

Now the problem is, lets assume I called the booking order form, containing the datagrid and I entered lets say 8 rows into the grid but I decided to void or commit these entries , when next I call up the booking form and I start entering rows , on getting to the ninth row I get this error message.

(Error Title: IndexOutOfRangedException was unhandled)
“Index 8 is either negative or above rows count.”


Now am feeling that some where some how reference is still being made or pointed to the initially order or transaction in the datagrid containing 8 rows, so any other additional row is being prevented from being added.

Also the Debugging error points to Frmbooking.showdialog() line of code (this calls the booking form). The booking form is named Frmbooking.

Also the below is the code should in case the user decides to void the transaction actually a windows form (Frmconfirmvoid) in the form of dialog box appears,clicking the “Yes” button is meant to clear everything on the form( items like the datagrid, the quantity label, total cost label, orderticket label and some other items , except the item/product buttons.


Private Sub BtnYes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnYes.Click
H_dt.Rows.Clear()
FrmBooking.GrpGarment.Visible = True
totgarment = Nothing
Extracost = Nothing
ExtracostFinalValue = Nothing
FrmBooking.TextBox4.Clear()
FrmBooking.lblQty.Text = 0
FrmBooking.HDGVLaundry.DataSource = Nothing

FrmBooking.LblProductpriceTotal.Text = 0
H_lngCounter = Nothing



FrmBooking.Close()

Me.Close()

End Sub
Please what am doing wrong.
regards
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900