473,796 Members | 2,538 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGridView: Preventing deselection of a selected checkbox

Hi all,

I have a DataGridViewChe ckBoxColumn 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 CellContentClic k 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 9229
a code sample would be nice.

tm

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

I have a DataGridViewChe ckBoxColumn 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 CellContentClic k 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(s trConn)
da = New SqlDataAdapter( "Select * From [Products]", conn)

da.Fill(ds, "Products")
DataGridView1.D ataSource = ds.Tables("Prod ucts")
DataGridView1.C olumns("Discont inued").ReadOnl y = True

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

I have a DataGridViewChe ckBoxColumn 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 CellContentClic k 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***@bellsout h.net> wrote in message
news:el******** *****@TK2MSFTNG P15.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******** ******@TK2MSFTN GP15.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******** ******@TK2MSFTN GP15.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...assumin g no
other field of the record is editable and thus able to alter rowstate?

tm

"Mike" <none> wrote in message news:er******** *****@TK2MSFTNG P10.phx.gbl...
"Toff McGowen" <tm@toff.com> wrote in message
news:ea******** ******@TK2MSFTN GP15.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
1601
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 Selected rows each time I select a new row. What am I doing wrong? private void dgrResults_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (((DataGridView)sender).CurrentCell is DataGridViewCheckBoxCell)
2
11063
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
1184
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
21309
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, iterate thru the dgv and update the bound fields if the cb has been checked. Then do the update and accept changes. How do I access the cb and its checked status? How to iterate thru dgv? Dim cbSelCol As New DataGridViewCheckBoxColumn
4
34076
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 checkboxes and the rows numbers
2
2769
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 System.InvalidOperationException was unhandled Edits to Textbox columns update without a problem. Any suggestion on what I'm doing wrong. Thanks... --
2
4296
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 checkboxes dont seem to work, and the datagridview throws a dataerror when I try to leave the cell after trying to check/uncheck the checkbox?!
2
6127
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 seems to return an error: "Formatted Value of the cell has wrong type". It works fine when the datagridview's editmode property is
0
2746
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 value(selected/not selected) for checkbox column for this event. The checkbox value is null. How can i get checkbox value(selected/not selected) using datagridview?
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10182
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10017
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7552
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5445
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.