Results 1 to 11 of 11

Thread: how to display data in DataGrid control

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    how to display data in DataGrid control

    please tell me how to display data in DataGrid control, the simplest way to do it. please this is very urgent to me

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: how to display data in DataGrid control

    What is your source of data? A recordset is best so you would only need to specify the binding to the grid.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    Re: how to display data in DataGrid control

    this is my code im using ADO
    Code:
    Private Sub Form_Load()
       
        Set Cn = New ADODB.Connection
        Cn.Provider = "Microsoft.Jet.OLEDB.4.0"
        Cn.ConnectionString = App.Path & "\db1.mdb"
        Cn.Open
        Set Rs = New ADODB.Recordset
        Rs.Open "Table1", Cn, adOpenDynamic, adLockOptimistic, adCmdTable
    End Sub
    my table has these fields
    f_name
    l_name
    address
    phone
    email

    i want to show them in the Data Grid, i never used this control before. please give me very simple solution

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: how to display data in DataGrid control

    I guess its best to figure out of a grid is the correct control for you..

    Are your users going to be editing records?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: how to display data in DataGrid control

    I have used about every grid control there is but this one because it relies on a formal data structure. However, I dug this up for you.

    "The DataGrid control in the "DataGrid Application" binds to a single DataSet object. The DataSet object of the "DataGrid Application" is initially populated from a database using an OleDbDataAdapter object.

    What is a DataGrid?
    The Windows Forms DataGrid control provides a user interface to ADO.NET datasets, displays ADO.NET tabular data in a scrollable grid, and allows for updates to the data source. In cases where the DataGrid is bound to a data source with a single table containing no relationships, the data appears in simple rows and columns, as in a spreadsheet. The DataGrid control is one of the most useful and flexible controls in Windows Forms. As soon as the DataGrid control is set to a valid data source, the control is automatically populated, by creating columns and rows based on the structure of the data. The DataGrid control can be used to display either a single table or the hierarchical relationships between a set of tables."
    ------------
    That's as far as I can take you. Hope this helps get you started.
    Doctor Ed

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    Re: how to display data in DataGrid control

    Quote Originally Posted by RobDog888
    I guess its best to figure out of a grid is the correct control for you..

    Are your users going to be editing records?
    please tell me both for editing and the Grid you said above

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: how to display data in DataGrid control

    Quote Originally Posted by Code Doc
    I have used about every grid control there is but this one because it relies on a formal data structure. However, I dug this up for you.

    "The DataGrid control in the "DataGrid Application" binds to a single DataSet object. The DataSet object of the "DataGrid Application" is initially populated from a database using an OleDbDataAdapter object.

    What is a DataGrid?
    The Windows Forms DataGrid control provides a user interface to ADO.NET datasets, displays ADO.NET tabular data in a scrollable grid, and allows for updates to the data source. In cases where the DataGrid is bound to a data source with a single table containing no relationships, the data appears in simple rows and columns, as in a spreadsheet. The DataGrid control is one of the most useful and flexible controls in Windows Forms. As soon as the DataGrid control is set to a valid data source, the control is automatically populated, by creating columns and rows based on the structure of the data. The DataGrid control can be used to display either a single table or the hierarchical relationships between a set of tables."
    ------------
    That's as far as I can take you. Hope this helps get you started.
    I think that is pertenant to VB.NET and not VB6
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: how to display data in DataGrid control

    Quote Originally Posted by chunk
    please tell me both for editing and the Grid you said above
    The datagrid doesnt allow editing (or at least without much code and questionable logic ) so if you need the users to be able to edit directly in the grid then you need to at best use a ListView and some semi-complicated code to "float" a textbox over the cell to "simulate" direct entry.

    Or use a 3rd party control.

    Or use a set of textboxes at the top or bottom of the grid for editing the selected record. Then click an update button and have it update th record and relad the grid for ex.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,515

    Re: how to display data in DataGrid control

    You can edit, add and delete the data in a DataGrid. Set the AllowUpdate, AllowAdd and AllowDelete property to True. Are you asking how to load data into a DataGrid?

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: how to display data in DataGrid control

    Ah so you can. Havent used it much at all. usually use Flexgrids or listviews. But still using a bound control is problematic when you want to do filtering and searches etc.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    Re: how to display data in DataGrid control

    thanks west4dbt, thanks Rob

    i have uploaded a simple example on my other thread please see that and just change the fields name in the data grid

    http://www.vbforums.com/showpost.php...63&postcount=4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width