Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridView
 

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?
Dopi  Sunday, April 09, 2006 4:32 PM

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.

Matty4242  Monday, April 10, 2006 11:55 AM
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?
Dopi  Monday, April 10, 2006 7:27 PM

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?

Matty4242  Wednesday, April 12, 2006 5:22 PM

You can use google to search for other answers

Custom Search

More Threads

• need to edit the values for a table and save it
• Connection Strings in Machine.Config and Table Adapter?
• Get a Pageframe Switch in a Button Click
• BindingSource Dispose() error Custom Handler cannot be converted
• can't use update method on my own dataadapter
• databound textbox issue
• DataGridView Button
• passing parameter to SQl server in vb2005
• Logical problem with DataGridViewComboBox based on a DataRelation
• Delete warning with bindingnavigator