none
bind data to datagridview RRS feed

  • Question

  • when i have a datatable, how can i bind one col. of datatable to datagridview as i only want to display one col. in dgv
    Wednesday, July 7, 2010 1:57 AM

Answers

  • you can bind your datatable with datagridview and set visibility false for all unrequired columns.

     

    regards

    jayant

    Wednesday, July 7, 2010 5:01 AM
  • Hello,

         After binding a datatable to your DataGridView, you can set

        datagridviewtest.Columns["unwanted2"].Visible = false;
        datagridviewtest.Columns["unwanted3"].Visible = false;
        datagridviewtest.Columns["unwanted4"].Visible = false;

        which are unwanted. Moreover, you can also set the visibility of unwanted columns in the designer.

     

    Thanks,

    Paras Sanghani

    Mark As Answer if it helped you.

    • Proposed as answer by jtorrecilla Wednesday, July 7, 2010 6:18 AM
    • Marked as answer by Jing0Moderator Thursday, July 15, 2010 2:45 AM
    Wednesday, July 7, 2010 6:15 AM
  •  

    Another workaround if you only want to display the value or use combobox to select:

     

    You can add a datagridviewComboBoxColumn and set it datasource to that table, set this column’s value member to the column name in the datatable.

    DataGridViewComboBoxColumn Class

    http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcolumn.aspx

     

    Set datagridviewComboboxColumn.DisplayStyle to “Nothing” to make the comboboxcolumn show up as textbox column.

    Related FAQ:

    5.  How do I  make the DataGridViewComboBoxColumn show  up as a text box column when not in edit mode?

     

    If there is anything unclear, please feel free to ask.

    Bests regards,

    Ling Wang


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Tuesday, July 13, 2010 7:03 PM
    Moderator

All replies

  • you can bind your datatable with datagridview and set visibility false for all unrequired columns.

     

    regards

    jayant

    Wednesday, July 7, 2010 5:01 AM
  • Hello,

         After binding a datatable to your DataGridView, you can set

        datagridviewtest.Columns["unwanted2"].Visible = false;
        datagridviewtest.Columns["unwanted3"].Visible = false;
        datagridviewtest.Columns["unwanted4"].Visible = false;

        which are unwanted. Moreover, you can also set the visibility of unwanted columns in the designer.

     

    Thanks,

    Paras Sanghani

    Mark As Answer if it helped you.

    • Proposed as answer by jtorrecilla Wednesday, July 7, 2010 6:18 AM
    • Marked as answer by Jing0Moderator Thursday, July 15, 2010 2:45 AM
    Wednesday, July 7, 2010 6:15 AM
  •  

    Another workaround if you only want to display the value or use combobox to select:

     

    You can add a datagridviewComboBoxColumn and set it datasource to that table, set this column’s value member to the column name in the datatable.

    DataGridViewComboBoxColumn Class

    http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcolumn.aspx

     

    Set datagridviewComboboxColumn.DisplayStyle to “Nothing” to make the comboboxcolumn show up as textbox column.

    Related FAQ:

    5.  How do I  make the DataGridViewComboBoxColumn show  up as a text box column when not in edit mode?

     

    If there is anything unclear, please feel free to ask.

    Bests regards,

    Ling Wang


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Tuesday, July 13, 2010 7:03 PM
    Moderator