Rabu, 04 Februari 2009

Problem with datagridview and checkboxcolumn. vb 2005


I have a form with a datagridview on it. This datagridview is used to display saved tests. When the user clicks a saved test a dialog box is displayed to display certain details of the saved test. The details are displayed in a datagrid view on the dialog box. The datagridview has a checkboxcolumn that was added through the datagridview tasks wizard. Two additional columns are bound to a dataset during the dialog box load event. I add a check mark to each check box with

Dim r As System.Windows.Forms.DataGridViewRow
With Me.DataGridView1
For Each r in .Rows
r.Cells("Column1").Value = 1
Next
End With

Everything works great the first time that the dialog box is displayed. The value for each check box cell is 1. However, if I close the dialog box and then reopen it the check boxes do not get checked and there is no value for the check box cells.

I created a button to run the code above and this will check the check boxes if the button is clicked, but if I click the button programatically nothing happens.

Has anyone else experienced this?

Thank you.


code

I think the problem was coming from having bound and unbound columns. I am now adding the data with a For Next loop and everything works corectly.

Me.DataGridView1.Rows.Clear()

Dim j as Integer
Try
For j = 0 To dsLeakAreas.Tables(0).Rows.Count - 1
DataGridView1.Rows.Add()
DataGridView1.Item(0, j).Value = CheckState.Checked
DataGridView1.Item(1, j).Value = dsLeakAreas.Tables(0).Rows(j).Item("LeakLocation")
DataGridView1.Item(2, j).Value = dsLeakAreas.Tables(0).Rows(j).Item("Notes")
Next
Catch ex As Exception
Throw New Exception(ex.message)
End Try


Edited by - gjc on 4/28/2008




source :http://www.vbcity.com

-------------------------------------------------------

Trik Gambar Bergerak

Trik Gambar-dimouse

Trik hapus pwd mysql

Trik insertin to db

Trik jadi root dilinux

Trik jam-distatus-bar

Trik Koneksi-ke database

Trik Koneksi-msql-php

Trik lihat-database-mysql

Trik membahas-fungsi-else

Trik member-area