none
Get DatagrivComboboxColumn Display Member RRS feed

  • Question

  • Hi! I am having difficulties to get the displayed member from datagridview cell.

    Usually we get the value from combobox instead of the displayed member, this time i want to get the displayed member of DataGridViewComboBoxColumn instead of the value.

    if we're doing this datagrid.rows(x).cell(x).value then we're getting the value, so how can i get the displayed member from the datagrid cell???

    Thanks!!

    Tuesday, September 25, 2012 7:25 AM

Answers

  • Hi Cmiiw,

    So please try this code snippet to get the one you wanted:

                Dim cc As DataGridViewComboBoxCell = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex)
                Console.WriteLine(cc.DisplayMember)
                Console.WriteLine(cc.ValueMember)
                Console.WriteLine(cc.Value)
                Console.WriteLine(cc.FormattedValue)

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by x4vier Friday, September 28, 2012 9:33 AM
    Friday, September 28, 2012 9:07 AM
    Moderator

All replies

  • I think you are just missing ToString() and cell should be cells.

    datagrid.rows(x).cells(x).value.ToString()


    Tuesday, September 25, 2012 6:49 PM
  • Hi X4vier,

    Welcome to the MSDN Forum.

    Do you mean the value of  property Displaymember: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcell.displaymember.aspx 

    So you can try "datagrid.rows(x).cell(x).displaymember"

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, September 26, 2012 11:15 AM
    Moderator
  • Hi X4vier,

    Welcome to the MSDN Forum.

    Do you mean the value of  property Displaymember: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcell.displaymember.aspx 

    So you can try "datagrid.rows(x).cell(x).displaymember"

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    it's like this :

    i have a DataGridViewComboBoxColumn which is load from database.

    in this case, i have loaded the DataGridViewComboBoxColumn from table item

    which have the displayed member = "item_name" and value member = "item_id"

    if i'm using datagrid.rows(x).cells(x).value.ToString() then i'm getting the value, now how can i get the displayed member???

    by the way

    i have tried to use this code "datagrid.rows(x).cell(x).displaymember", but this code doesn't exist (i'm using vb.net in visual studio 2010)

    CMIIW

    Wednesday, September 26, 2012 11:45 AM
  • Hi Cmiiw,

    >>i have tried to use this code "datagrid.rows(x).cell(x).displaymember", but this code doesn't exist 

    Please try this code: 

    Console.WriteLine(DirectCast(DataGridView1.Rows(0).Cells(0), DataGridViewComboBoxCell).DisplayMember)

    I hope this is clear.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 27, 2012 10:12 AM
    Moderator
  • Hi Cmiiw,

    >>i have tried to use this code "datagrid.rows(x).cell(x).displaymember", but this code doesn't exist 

    Please try this code: 

    Console.WriteLine(DirectCast(DataGridView1.Rows(0).Cells(0), DataGridViewComboBoxCell).DisplayMember)

    I hope this is clear.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Sorry to bother you again

    well, if i'm using this code

    Console.WriteLine(DirectCast(DataGridView1.Rows(0).Cells(0), DataGridViewComboBoxCell).DisplayMember)

    then the returning value is "item_name"

    well those are not the one i'm looking for......

    it's like this in the DataGridViewComboBoxColumn which was displayed to the user, i have something like this

    item_name item_value

    computer 1

    HardDisk 2

    Monitor 3

    etc....

    so how can i get the computer, hardisk or monitor instead of the value which is: 1,2,3, etc.....


    • Edited by x4vier Thursday, September 27, 2012 1:00 PM
    Thursday, September 27, 2012 1:00 PM
  • Hi Cmiiw,

    So please try this code snippet to get the one you wanted:

                Dim cc As DataGridViewComboBoxCell = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex)
                Console.WriteLine(cc.DisplayMember)
                Console.WriteLine(cc.ValueMember)
                Console.WriteLine(cc.Value)
                Console.WriteLine(cc.FormattedValue)

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by x4vier Friday, September 28, 2012 9:33 AM
    Friday, September 28, 2012 9:07 AM
    Moderator
  • Console.WriteLine(cc.FormattedValue)

    this is the one that i'm looking for, thank you so much :D

    Friday, September 28, 2012 9:33 AM