DataGridView

Ok, so I have six Colums that are all loaded into the DataGridView, each coloumn as info in it. How could I get the text of each selected item in the 2 column I know about the The DataGridViewRow and the DataGridViewCellCollection and all that stuff, but I dont know how to use it. NAy ideas



Answer this question

DataGridView

  • TAO DE ZHI

    First, this should be a separate thread because it is a separate problem.

    Second, try to describe the problem in the subject line.

    Stupid question - do you have the ReadOnly property of the DataGridView set to True


  • TKelley

    Assuming a reference to a DataGridView control has been established in the "dgv" variable:

    Dim Row as DataGridViewRow

    Dim Col2Str as String

    For Each Row in dgv.SelectedRows

    Col2Str = Row.Cells(2).Value.ToString

    ...

    Next Row

    And that's the clumn whose index is 2, which is usually the third column.

    Hope this helps.


  • MPSIperson

    Well, this is my C# conversion, for those who are wondering..

    string Col2Str;

    foreach (DataGridViewRow Row in this.dataGridView1.SelectedRows)
    {
    Col2Str = Row.Cells[2].Value.ToString();
    MessageBox.Show(Col2Str);
    }

    My nex question. I use this code, to add check boxes to th DGV.

        private void AddOutOfOfficeColumn()
            {
      DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
                {
                    column.AutoSizeMode =
                        DataGridViewAutoSizeColumnMode.AllCells;
                    column.FlatStyle = FlatStyle.Standard;
                    column.Selected = false;
                }

                dataGridView1.Columns.Insert(0, column);
            }

    And It adds them fine, but when I click them nothing happens (theyu dont check themselves) why is that How can I fix it


  • DataGridView