4 Replies - 1188 Views - Last Post: 03 March 2017 - 03:10 PM Rate Topic: -----

#1 sc5502  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 21-April 16

Empty data grid view

Posted 03 March 2017 - 01:39 PM

How do you determine when a data grid view is empty and display "No records found" in the body of the data grid view?
VB.net

This post has been edited by sc5502: 03 March 2017 - 01:42 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Empty data grid view

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13485
  • View blog
  • Posts: 53,847
  • Joined: 12-June 08

Re: Empty data grid view

Posted 03 March 2017 - 01:41 PM

Why is this in 'nightmare in code'?

What language is it for?
How are you filling your grid?
What have you tried?
Was This Post Helpful? 0
  • +
  • -

#3 sc5502  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 21-April 16

Re: Empty data grid view

Posted 03 March 2017 - 01:47 PM

language is vb; no I have not

Try
            Dim connectionString As String = g_SQL_SupplierEvaluations

            Dim connection As New SqlConnection(connectionString)
            Dim dataadapter As New SqlDataAdapter(qry, connection)
            Dim ds As New DataSet()
            connection.Open()
            dgv_Ratings.DataSource = DBNull.Value
            dataadapter.Fill(ds, "dgv")
            ' dataadapter.Fill(ds)
            connection.Close()
            dgv_Ratings.DataSource = ds
            dgv_Ratings.DataMember = "dgv"
            dgv_Ratings.Columns.Item("ID_Supplier").Visible = False
            dgv_Ratings.Columns.Item("FY").Width = 40
            dgv_Ratings.Columns.Item("QTR").Width = 45

            With dgv_Ratings.ColumnHeadersDefaultCellStyle
                .Font = New Font(dgv_Ratings.Font, FontStyle.Bold)
            End With
            With Me.dgv_Ratings
                .RowsDefaultCellStyle.BackColor = Color.Bisque
                .AlternatingRowsDefaultCellStyle.BackColor = Color.Beige
            End With

        Catch EX As Exception
            MsgBox(EX.Message)

            Exit Sub
        End Try

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13485
  • View blog
  • Posts: 53,847
  • Joined: 12-June 08

Re: Empty data grid view

Posted 03 March 2017 - 01:51 PM

Moved out of 'night mare in code' and in to the vb.net forum.

One would figure you would look at your dataset's datatable you use to back your grid. If no rows then.. well.. no rows.
Was This Post Helpful? 0
  • +
  • -

#5 maceysoftware  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 348
  • View blog
  • Posts: 1,493
  • Joined: 07-September 13

Re: Empty data grid view

Posted 03 March 2017 - 03:10 PM

AS Modi has said you could check the DataSource's data to see if any data exists. You are Databound to a DataSet so you would need to look at the table of data your interested and get the RowCount.

You could also just check to see the datagridview row count. All i can say is give it a go and if you get stuck show us your efforts and we can give you a nudge in the right direction.

As far as displaying the "No records found" in the body of the DataGridView. There is no real way to do this out of the box with the DataGridView, however if you wanted to do this then two options you have is create a row and display it in a column data (not nice but gets the job done)

The other option is that you could have a label located behind the DataGridView which you bring to front when there is no rows. But if the row count changes then you would need to check again to see if the label should still be visible or if you send it to back.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1