Windows Develop Bookmark and Share   
 index > Windows Forms Designer > datagridview showing no grid
 

datagridview showing no grid

I added a datagridview control to a form (VS 2005), filled with data at form load time. The datagridview control keeps being grey, not showing any grid at all.. I have another example working properly but,.... I can't see the difference... Any hint, please?
thx
amc  Saturday, January 06, 2007 8:32 AM
Could you post a code snippet?
Marinus Holkema  Saturday, January 06, 2007 9:11 AM
here you are, the code from the form
=============================================
Imports BL
'
'
'
Public Class EmpInfo
Inherits System.Windows.Forms.Form

' Private mdsEmps As BL.EmpService.Employees
Private mdsEmps As New DataSet

Private Sub EmpInfo_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

GridLoad()



End Sub
'
'
'
Public Sub GridLoad()

Dim br As BL.Employees

Me.grdEmps.Visible = True
Me.grdEmps.Enabled = True
Me.grdEmps.BackgroundColor = Color.Aquamarine
Me.grdEmps.BringToFront()
Me.grdEmps.ColumnHeadersVisible = True
Me.grdEmps.EnableHeadersVisualStyles = True
Me.grdEmps.Show()

Try
br = New BL.Employees()
Dim dt As New DataTable

' mdsEmps is a UNTyped dataset on this form

mdsEmps = br.GetData()
dt = mdsEmps.Tables(0)
Me.grdEmps.DataSource = dt 'mdsEmps.Tables(0)
Me.grdEmps.DataMember = "FirstName"

MessageBox.Show(mdsEmps.Tables(0).Rows(0).Item("FirstName").ToString & vbCrLf & _
dt.Rows(0).Item("FirstName").ToString)

Catch exp As Exception
MsgBox(exp.Message)
End Try

If mdsEmps.Tables(0).Rows.Count = 0 Then
MessageBox.Show(mdsEmps.Tables(0).Rows.Count.ToString)
End If
End Sub
end class
amc  Saturday, January 06, 2007 8:16 PM
By removing the sentence Me.grdEmp.Datamember="FirstName" the DataGridView is displayed properly

I don't know the reason, though
amc  Saturday, January 06, 2007 9:15 PM

The DataMember should be set to the name of the table. You could use:

Me.grdEmps.DataMember = mdsEmps.Tables(0).TableName

Marinus Holkema  Monday, January 08, 2007 8:12 AM

You can use google to search for other answers

Custom Search

More Threads

• DesignerSurface.CreateDesigner returns null - security problem?
• KEyboard Control
• Disable scroll bars in a mdicontainer form
• Forms Designer Can´t Show it
• Errors when changing more than a few controls at a time
• Bug in Forms Designer
• RichTextBox that grows and shrinks to fit content
• VS 2005 Copy and Paste a Form in Solution Explorer
• Visual Studio 2005 MaskedTextBox
• Continuous Forms