473,413 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

DataGridView: Preventing deselection of a selected checkbox

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
8 9208
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
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
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
"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
"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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: GS | last post by:
Hi, I have dataGridView with MultupleSelect property enabled and I programmatically set rows to be Selected based on checkbox being selected in DataGrid (code below). Issue is that it resets...
2
by: Kiran_Juikar | last post by:
How to add the header checkbox in the datagridview checkbox column? Is there any property available to add a header checkboxor one need to write the custom logic for this?
0
by: axas | last post by:
After a deselection of all the items of a listbox, the first item appears selected again. How can I fix it????
4
by: Hexman | last post by:
Hello All, I'd like to find out the best way to add a cb column to a dgv and process efficiently. I see at least two ways of doing it. ------------------------------- 1) Add a cb to the dgv,...
4
by: Annie | last post by:
hello guys, I am having a DataGridView control. The first column is a checkbox column. The users can select the checkbox column. I need to loop through the grid rows and get the checked...
2
by: =?Utf-8?B?VG9ueSBBLg==?= | last post by:
I have a datagridview on a Windows form where one of the columns is a checkbox. After checking or unchecking the checkbox I try to update the database. The following error appears ...
2
by: mrstrong | last post by:
Gday, I have a datagridview that I am creating the columns programatically which all seems to work fine. I have a couple of dropdown boxes, so I have set the editMode= EditOnEnter. Now my...
2
by: mrstrong | last post by:
Gday, Why would all my checkboxes inside a datagridview stop working (ie checked state not updating when user clicks) when the datagridview's editmode property is changed to "EditOnEnter"? It...
0
by: tramesh2007 | last post by:
I am using datagridviewcheckbox column in datagridview. I have a probelm for clicking checkbox column. The problem is, On datagrid_CellMouseClick event, for clicking checkbox when getting...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.