Results 1 to 3 of 3

Thread: Ways to populate a datagridview

  1. #1
    motorola is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2011
    Posts
    3
    Reputation
    0

    Ways to populate a datagridview

    This code works normal for normal situation:
    Code:
    DataGridView1.DataSource = Datatable1
    The problem with this code is that I must arrange the order of the fields in the select statement. How do I add rows to the datagridview manually and preset the order of the columns by myself?
    The reason I want to do this is because I want to add buttons and dtPicker within the datagridview, and I cannot see how I can achieve this using the snippet above. And that creates a second question : how do I embed button and dtPicker to a datagridview?

    Thanks

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,339
    Reputation
    1543
    You can add columns to the grid in the designer. There are several predefined column types, including one for Buttons. There is not one for DateTimePickers though. One option is to create your own custom column type, which Microsoft has already kindly done for you (although it could use a bit of improvement).

    How to: Host Controls in Windows Forms DataGridView Cells

    You can add bound or unbound columns in the designer. Adding bound columns will fix your column order issue. You can add a column and set its DataPropertyName property. When you bind the grid, i.e. set its DataSource, the grid column will then display data from the data source column or property with the specified name. Alterantively, you can simply bind the grid and let it create the columns, then set the DisplayIndex of each one to show them in the order you want.

  3. #3
    motorola is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2011
    Posts
    3
    Reputation
    0
    How do I add bound columns? I tried accessing datasource property of the grid via properties window and chose Add New Project Data Source. I'm having trouble connecting to the MySQL Database. This connection string worked in my code : "Server=localhost;Port=3306;Database=test;Uid=root ;Pwd=kxtg2431;Encrypt=true;"
    but won't run during the datagrid datasource configuration. I've also added the mysql connector in to my project. Help? Thanks

Bookmarks

Posting Permissions

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