By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,612 Members | 1,647 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,612 IT Pros & Developers. It's quick & easy.

DataGridView: Preventing deselection of a selected checkbox

P: n/a
Hi all,

I have a DataGridViewCheckBoxColumn as one of my columns in a DataGridView.
I want this checkbox to only be checked, but not unchecked - it's used by
the user to audit that they have "seen" and checked an order.

In VB6 I would handle the Mouse Button Down event, test the target cell and
set the mouse event arguements to nothing. This doesn't actually work in
..NET, allowing the user to deselect the checkbox.

If I put the logic in the CellContentClick event to test whether the user is
selecting an already checked cell and keeping the cell checked - this also
doesn't work.

I can, however test for the value of the checkbox and set/unset other
checkboxes on the same row; but no matter what I set the original target
checkbox to, I can't get .NET to prevent the user from deselecting a
selected checkbox.

Any ideas what I'm doing wrong?

Thanks!

Mike
Jan 26 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
a code sample would be nice.

tm

"Mike" <none> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Hi all,

I have a DataGridViewCheckBoxColumn as one of my columns in a DataGridView. I want this checkbox to only be checked, but not unchecked - it's used by
the user to audit that they have "seen" and checked an order.

In VB6 I would handle the Mouse Button Down event, test the target cell and set the mouse event arguements to nothing. This doesn't actually work in
.NET, allowing the user to deselect the checkbox.

If I put the logic in the CellContentClick event to test whether the user is selecting an already checked cell and keeping the cell checked - this also
doesn't work.

I can, however test for the value of the checkbox and set/unset other
checkboxes on the same row; but no matter what I set the original target
checkbox to, I can't get .NET to prevent the user from deselecting a
selected checkbox.

Any ideas what I'm doing wrong?

Thanks!

Mike

Jan 26 '06 #2

P: n/a
Mike,

There is no DataGrid in VB6, so you cannot handle that in VBNet. Maybe is
there something as a FlexGrid, however that is completely different.

Be aware that Data controls in VBNet use forever the underlying DataSource.
That means that the best way to handle those Data controls is to access them
by the DataSource and not direct in the control.

I hope this helps,

Cor
Jan 26 '06 #3

P: n/a
Hi,

You can always make the column read only.

Dim strConn As String
Dim da As SqlDataAdapter
Dim conn As SqlConnection
Dim ds As New DataSet

strConn = "Server = .;"
strConn &= "Database = NorthWind; Integrated Security = SSPI;"
conn = New SqlConnection(strConn)
da = New SqlDataAdapter("Select * From [Products]", conn)

da.Fill(ds, "Products")
DataGridView1.DataSource = ds.Tables("Products")
DataGridView1.Columns("Discontinued").ReadOnly = True

Ken
-------------------
"Mike" <none> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Hi all,

I have a DataGridViewCheckBoxColumn as one of my columns in a
DataGridView. I want this checkbox to only be checked, but not unchecked -
it's used by the user to audit that they have "seen" and checked an order.

In VB6 I would handle the Mouse Button Down event, test the target cell
and set the mouse event arguements to nothing. This doesn't actually work
in .NET, allowing the user to deselect the checkbox.

If I put the logic in the CellContentClick event to test whether the user
is selecting an already checked cell and keeping the cell checked - this
also doesn't work.

I can, however test for the value of the checkbox and set/unset other
checkboxes on the same row; but no matter what I set the original target
checkbox to, I can't get .NET to prevent the user from deselecting a
selected checkbox.

Any ideas what I'm doing wrong?

Thanks!

Mike

Jan 26 '06 #4

P: n/a
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:el*************@TK2MSFTNGP15.phx.gbl...
Hi,

You can always make the column read only.


Thanks Ken,

The problem with that is, I want to be able to make it read/write so that it
can be selected the first time. Another bug that your code sample would
introduce is that I would set >all< cells in that column to read only.

I'm sure there must be an easier way of preventing a user click on an
already selected checkbox in a datagridview.

M
Jan 27 '06 #5

P: n/a
"Toff McGowen" <tm@toff.com> wrote in message
news:ea**************@TK2MSFTNGP15.phx.gbl...
a code sample would be nice.


No code, at the moment it's just a datagridview bound to a datatable. One of
the columns is of a checkbox type.

I want to prevent deselection after selection - EVEN if the selection was
inadvertant.

M
Jan 27 '06 #6

P: n/a
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:OG**************@TK2MSFTNGP15.phx.gbl...
Mike,

There is no DataGrid in VB6, so you cannot handle that in VBNet. Maybe is
there something as a FlexGrid, however that is completely different.
There are grids and controls in VB6 that you can catch the mouse events on
and set the mouse parameters to nothing such that the mouse click event is
effectively cancelled.
Be aware that Data controls in VBNet use forever the underlying
DataSource. That means that the best way to handle those Data controls is
to access them by the DataSource and not direct in the control.


Fair enough, but that still won't prevent deselection of a selected
checkbox.

M
Jan 27 '06 #7

P: n/a
Oh. Then checking the check box will alter the rowstate of the underlying
record.
If the rowstate is modified then prevent/reset check state...assuming no
other field of the record is editable and thus able to alter rowstate?

tm

"Mike" <none> wrote in message news:er*************@TK2MSFTNGP10.phx.gbl...
"Toff McGowen" <tm@toff.com> wrote in message
news:ea**************@TK2MSFTNGP15.phx.gbl...
a code sample would be nice.
No code, at the moment it's just a datagridview bound to a datatable. One

of the columns is of a checkbox type.

I want to prevent deselection after selection - EVEN if the selection was
inadvertant.

M

Jan 27 '06 #8

P: n/a
Mike,

Why not however using the validating event from the checkbox will probably
more easy.

This is about the textbox however the checkbox will probably go as well. (I
did not try that)

http://www.vb-tips.com/default.aspx?...d-203ca99d2825

Otherwise you can try it (for the underlying datasource) in the row change
event of that datasource.

And if you real want it up to date, than you van evaluate the datasource
like this. (a little bit ugly method)

http://www.vb-tips.com/default.aspx?...8-1def3152436f

I hope this helps,

Cor
Jan 27 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.