Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Initial Form load doesn't display data in datagridview

$
0
0

The form loads. The datagridview displays the number of rows you would expect to see, but the cells are empty. I click on ANY button on the form (including just a filter dropdown) and the datagridview cells are populated with the data.

It appears to me that the filter has something to do with this, but I could easily be mistaken.

Just to be clear, everything works. The issue is that when the form initially loads, the datagridview doesn't display any data. I've even tried using the "processClick" method to see if i can get programmatically get around the issue, but it doesn't work. I've also tried to use Refresh on the datagridview and the form.

Form

    Private Sub frmTemplate_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Load_cboWebSite()
        LoadData()
    End Sub

    Private Sub Load_cboWebSite()
        Dim items As mvItemList = recSiteMaster.ItemsList
        Dim binditemsList As New List(Of DictionaryEntry)
        For Each item As mvItem In items
                binditemsList.Add(New DictionaryEntry(item("WEB_SITE"), item("DESC")))  
        Next
        cboWebSite.ValueMember = "key"
        cboWebSite.DisplayMember = "value"
        cboWebsite.DataSource = binditemsList
    End Sub  'Load_cboWebSite

    Private Sub LoadData()
        ' Load data from record into screen objects (text boxes, etc.)
        Dim Message = ""
        Dim Caption = Me.Text
        Dim Buttons As MessageBoxButtons = MessageBoxButtons.OK
        Dim DefaultButton As MessageBoxDefaultButton = DefaultButton
        Dim Icon As MessageBoxIcon = MessageBoxIcon.Error
        Dim escaped As Boolean = False
        Try
            'load all fields from <prefix>.webmgt
            LoadRecWebMgt()
        Catch ex As Exception
            Message = "Failed while attempting to read from the database."
            MessageBox.Show(Message, Caption, Buttons, Icon, DefaultButton)
        End Try
        'Load DCS dropdown
        Load_DCSFilter()
        'Load DataSet
        LoadDataset_dtsWebMgt()
        'Load DataGridView
        Load_dgvWebContentMgt()
    End Sub  'LoadData

    Private Sub LoadRecWebMgt()
        'Load record from database
        Dim Message = ""
        Dim Caption = Me.Text
        Dim Buttons As MessageBoxButtons = MessageBoxButtons.OK
        Dim DefaultButton As MessageBoxDefaultButton = DefaultButton
        Dim Icon As MessageBoxIcon = MessageBoxIcon.Error
        Dim selectControl As New mvSelect
        Dim itemsWebMgt As mvItemList = Nothing
        Dim webItem As New mvItem
        Dim webMgtId As String = ""
        Dim webIdx As Int16 = 0
        Dim lPrdGrp As List(Of String) = New List(Of String)
        Dim localrecWebMgt As New classHUWebMgt
        selectControl.SortClause = sortClause
        selectControl.RetrievalStyle = RetrievalStyle.AllDataInitially
        selectControl.RetrievalSizeOnDemand = 10
        selectControl.RetrievalSizeInitial = 50
        selectControl.Attributes = "1 "
        Try
            Dim fileWebMgt As New mvFile(HubertAccount, filePrefix & "." & "WEBMGT")
            itemsWebMgt = fileWebMgt.Select(selectControl)
        Catch ex As Exception
            HubertMessageBox.Show(ex.Message, Caption, Buttons, Icon)
        End Try
        'Add recordId's to a list
        lItem.Clear()
        lDesc.Clear()
        lPrdGrp.Clear()
        mvRecWebMgt.Clear()
        Do Until itemsWebMgt.EOL
            webItem = itemsWebMgt.ReadNext
            localrecWebMgt.dataRec = webItem
            mvRecWebMgt.Add(localrecWebMgt.dataRec)
            lItem.Add(localrecWebMgt.dataRec.Data(0))
            lPrdGrp.Add(localrecWebMgt.PRD_GRP)
            lDesc.Add(localrecWebMgt.DESC)
        Loop
        'Add virtual field, DESC, to a list
        'lDesc.Clear()
        'lDesc.AddRange(Split(recWebMgt.DESC, Chr(253)))
        'Get the DCS code from the PRD_GRP field (1st character on left): save to list
        Dim prev As String = ""
        'lPrdGrp.AddRange(Split(recWebMgt.PRD_GRP, Chr(253)))
        lPrdGrp.Sort()
        lDCS.Clear()
        lFilteredDCS.Clear()
        lFilteredDCS.Add("")  'Allow user to select an empty string
        For Each element As String In lPrdGrp
            lDCS.Add(Strings.Left(element, 1))
            If Strings.Left(element, 1) <> Strings.Left(prev, 1) Then
                lFilteredDCS.Add(Strings.Left(element, 1))
                prev = element
            End If
        Next
    End Sub 'LoadRecWebMgt

    Private Sub Load_DCSFilter()
        If Not IsNothing(lFilteredDCS) Then
            cboDCSFilter.ValueMember = "key"
            cboDCSFilter.DisplayMember = "value"
            cboDCSFilter.DataSource = lFilteredDCS
        End If
    End Sub  'Load_DCSFilter

    Private Sub LoadDataset_dtsWebMgt()
        Dim arWebMgt As New ArrayList()
        Dim oRowData As Object() = Nothing
        Dim sRowData As String = ""
        Dim dDate As Date
        Dim recCount As Integer = 0
        Try
            recCount = mvRecWebMgt.Count
            For rowIdx As Integer = 1 To recCount
                'Columns 0 - 15
                dDate = GetDate(mvRecWebMgt.Item(rowIdx).Data(unidata_WebMgt.DatePublished))
                If dDate <= Date.Now.AddDays(PUBLISHED_DAYS_BEFORE_DROPOFF) Then
                    sRowData = mvRecWebMgt.Item(rowIdx).Data(unidata_WebMgt.Item) & MV & lDesc(rowIdx - 1) & MV & mvRecWebMgt.Item(rowIdx).Data(unidata_WebMgt.WhoPriced) & Chr(253) & Chr(253) & mvRecWebMgt.Item(rowIdx).Data(unidata_WebMgt.WhoChangedSpecs) & Chr(253) & Chr(253) & Chr(253) & Chr(253) & Chr(253) & mvRecWebMgt.Item(rowIdx).Data(unidata_WebMgt.WhoUpdatedWebContent) & Chr(253) & Chr(253) & Chr(253) & Chr(253) & Chr(253) & mvRecWebMgt.Item(rowIdx).Data(unidata_WebMgt.WhoPublished) & Chr(253) & lDCS(rowIdx - 1)
                    arWebMgt.Add(sRowData)
                End If
            Next
            myDataSet.WebMgt.Rows.Clear()
            For x As Integer = 0 To arWebMgt.Count - 1
                oRowData = arWebMgt(x).split(MV)
                myDataSet.WebMgt.Rows.Add(oRowData)
            Next
            Dim tables As DataTableCollection = myDataSet.Tables
            Dim vwWebMgt As New DataView(tables(0))
            bs.DataSource = vwWebMgt
        Catch ex As Exception
        End Try
    End Sub  'LoadDataset_dtsWebMgt

    'Build the grid using record data
    Private Sub Load_dgvWebContentMgt()
        dgvWebContentMgt.AutoGenerateColumns = False
        dgvWebContentMgt.DataSource = bs
        bs.Filter = filterString
        For rowIdx As Integer = 0 To bs.Count - 1
            For colIdx As Integer = 0 To myDataSet.Tables(0).Columns.Count - 1
                'add cell item
                dgvWebContentMgt.Rows(rowIdx).Cells(colIdx).Value = bs.Item(0).dataview.item(rowIdx).item(colIdx)
                Select Case (colIdx)
                    Case unidata_WebMgt.Item
                        If bRefreshedManually = True Then
                            dgvWebContentMgt.Rows(rowIdx).Cells(colIdx).Style.BackColor = Color.White
                        Else
                            For z As Integer = 0 To arListHighlightedItems.Count - 1
                                If rowIdx = arListHighlightedItems(z) Then
                                    dgvWebContentMgt.Rows(rowIdx).Cells(colIdx).Style.BackColor = HighlightColor
                                End If
                            Next
                        End If
                    Case ColumnIndex.PriceEntered
                        dgvWebContentMgt.Rows(rowIdx).Cells(colIdx).Style.BackColor = GetFlagColor(mvRecWebMgt.Item(rowIdx + 1).Data(unidata_WebMgt.PriceFlag).ToString())
                        dgvWebContentMgt.Rows(rowIdx).Cells(colIdx).ToolTipText = GetDate(mvRecWebMgt.Item(rowIdx + 1).Data(unidata_WebMgt.DatePriced))
                    Case ColumnIndex.ImageAvailable
                        dgvWebContentMgt.Rows(rowIdx).Cells(colIdx).Style.BackColor = GetFlagColor(mvRecWebMgt.Item(rowIdx + 1).Data(unidata_WebMgt.ImageAvailable).ToString())
                        dgvWebContentMgt.Rows(rowIdx).Cells(colIdx).ToolTipText = GetDate(mvRecWebMgt.Item(rowIdx + 1).Data(unidata_WebMgt.ImageDate))
                    Case ColumnIndex.SpecComplete
                        dgvWebContentMgt.Rows(rowIdx).Cells(colIdx).Style.BackColor = GetFlagColor(mvRecWebMgt.Item(rowIdx + 1).Data(unidata_WebMgt.SpecificationStatus).ToString())
                        dgvWebContentMgt.Rows(rowIdx).Cells(colIdx).ToolTipText = GetDate(mvRecWebMgt.Item(rowIdx + 1).Data(unidata_WebMgt.SpecDate))
                    Case ColumnIndex.ItemInStock
                        dgvWebContentMgt.Rows(rowIdx).Cells(colIdx).Style.BackColor = GetFlagColor(mvRecWebMgt.Item(rowIdx + 1).Data(unidata_WebMgt.InStockFlag).ToString())
                        'dgvWebContentMgt.Rows(rowIdx).Cells(colIdx).ToolTipText = recWebMgt.dataRec(unidata_WebMgt.????, rowIdx).ToString()
                    Case ColumnIndex.WebContent
                        dgvWebContentMgt.Rows(rowIdx).Cells(colIdx).Style.BackColor = GetFlagColor(mvRecWebMgt.Item(rowIdx + 1).Data(unidata_WebMgt.WebContentStatus).ToString())
                        dgvWebContentMgt.Rows(rowIdx).Cells(colIdx).ToolTipText = GetDate(mvRecWebMgt.Item(rowIdx + 1).Data(unidata_WebMgt.WebContentDate))
                    Case ColumnIndex.ReadyToPublish
                        dgvWebContentMgt.Rows(rowIdx).Cells(colIdx).Style.BackColor = GetFlagColor(mvRecWebMgt.Item(rowIdx + 1).Data(unidata_WebMgt.ReadyToPublishFlag).ToString())
                        'dgvWebContentMgt.Rows(rowIdx).Cells(colIdx).ToolTipText = recWebMgt.dataRec(unidata_WebMgt.?????, rowIdx).ToString()
                    Case ColumnIndex.Published
                        dgvWebContentMgt.Rows(rowIdx).Cells(colIdx).Style.BackColor = GetFlagColor(mvRecWebMgt.Item(rowIdx + 1).Data(unidata_WebMgt.Published).ToString())
                        dgvWebContentMgt.Rows(rowIdx).Cells(colIdx).ToolTipText = GetDate(mvRecWebMgt.Item(rowIdx + 1).Data(unidata_WebMgt.DatePublished))
                    Case Else
                        'do nothing with this column
                End Select
            Next
        Next
        dgvWebContentMgt.Refresh()
    End Sub 'Load_dgvWebContentMgt


Thanks! ~Gone2TheDogs


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>