CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2012

    [RESOLVED] VB.NET--DataGridView Columns

    Hello all,

    I'm working on a project with a DataGridView that is filled using a SQL connection. Is there a way to modify (code-behind) the number/names of columns in the DataGridView based upon the fields retrieved by the SQL string?

    *Databinding is not an option because I have multiple functions for the DataGridView depending upon a radio button option and each function retrieves different SQL data.

    Thank you for your time!

  2. #2
    Join Date
    Aug 2009
    NW USA

    Re: VB.NET--DataGridView Columns

    You can Add columns to the DGV programatically. That way you can dictate the HeaderText, DefaultCellStyle, etc. The important thing, when you are adding a column, is to set the DataPropertyName. This needs to correspond to your data source. If you retreive a column of data and there is no column in the DGV with that specific DataPropertyName the DGV will create a column, and it won't look nice.

  3. #3
    Join Date
    Jul 2012

    Re: VB.NET--DataGridView Columns

    Thank you Mur16. Apparently I've been an air-head all day. I had pre-defined columns setup in design-view. Problem solved.

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.