'''My Load Event Code which creates all database controls , fetches data from the datagridview and arranges them in the panel: Dim Dayz As Int32 = 30 For i As Int32 = 1 To Dayz Dim datagridview1 As New DataGridView() datagridview1.Name = i.ToString() AddHandler datagridview1.CellDoubleClick, AddressOf CellDoubleClick Dim col As New DataGridViewTextBoxColumn col.HeaderText = i.ToString() datagridview1.Columns.Add(col) datagridview1.AutoGenerateColumns = False 'gets data from SQL SQL.RunQuery("SELECT Subject FROM Appointments WHERE Day = '" & i.ToString() & "'AND Year = '" & textBoxYear.Text & "'AND Month = '" & lbl_Month.Text & "' AND Owner = '" & MainInterface.cbo_Users.Text & "'") If SQL.SQLDataset.Tables.Count > 0 Then For Each R As DataRow In SQL.SQLDataset.Tables(0).Rows datagridview1.DataSource = SQL.SQLDataset.Tables(0) For k As Integer = 0 To datagridview1.Columns.Count - 1 datagridview1.Columns(k).DataPropertyName = "Subject" Next Next End If 'arranges all datagridview in the panel datagridview1.SetBounds(x, y, 151, 107) x += 153 If ndayz = 7 Then x = 0 ndayz = 0 y += 109 End If Panel1.Controls.Add(datagridview1) Next '' I do not have any issue with the above code. However in the doubleclick event, I get an Index out of range exception: Private Sub CellDoubleClick(sender As System.Object, e As DataGridViewCellEventArgs) Msgbox (datagridview1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) '''' I get an index out of range exception on this line. End Sub
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)