tags:

views:

188

answers:

2

I have a datagridview (unbound). Fields are Name, Family Name and Phone No and a checkbox colum.

There are ten rows in that DataGridView.

There is an OK button

I need to get message of showing which rows user has checked. The message should appear when user clicks OK button. There could be several message, checking each row one by one, in a loop.

I am not able to get this message. I tried following code in OK button

Dim strCB As String = dgvChooseQs.Rows(0).Cells(3).Value.ToString

Cell(3) is my checkbox. Donot consider Rows(0), at the moment I am just checking value at row 0

Thanks for your help.F

Furqan

A: 

You need to do something like this:

if ctype(dgvChooseQs.Rows(0).findcontrol("whateverYourCheckBoxIsNamed"), checkbox).checked then 

'throw the message

end if
aape
When I wrote your code, it saysfindcontrol is not the member of system.windows.forms.datagridviewrowplease check and advise
A: 

Do noy use the cell index. Your checkbox column must have a name so you should use it.

Otherwise, what you want to do would be something like this


For each oRow as DataGrisViewRow in dgvChooseQs.Rows

   If oRow.Cells("ColNamE").Value = True then
    'do whatever you need to do.
   End if

Next

If you feel you need to cast the column, then you can use CType, but the type is DataGrisViewCheckBoxCell, not CheckBox.

David Brunelle
I put your code in OK button. When run, the following line returned errorIf oRow.Cells("chkAdd").Value = True Thenconversion from string "" to type Bolean' is not validThis is what I received from many other code types too.Please help.
What type is you column ? Is it a DataGridViewTextBoxColumn or DataGridViewCheckBoxColumn ?More importantly, what version of Visual Studio are you running ?
David Brunelle
Thanks for responseI am running visual studio 2008my checkbox is datagridviecheckbox column
You can always Cast the cell since you know it's a CheckBox, try to change it to If Ctype(oRow.cells("chkAdd"),DataGridViewCheckBoxCell).Value.Note it might not be value, but some other property like Checked. I can't remember on top of my head.
David Brunelle
It works..........Great thanks
Cool. Normally, you would flag that post as the answer so that if someone else have the same problem, they'll know what to do.
David Brunelle