|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataGridView: Preventing deselection of a selected checkboxI 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 a code sample would be nice.
tm Show quoteHide quote "Mike" <none> wrote in message news:%23wocaChIGHA.532@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 > > "Toff McGowen" <t*@toff.com> wrote in message No code, at the moment it's just a datagridview bound to a datatable. One of news:eaNRd7hIGHA.3700@TK2MSFTNGP15.phx.gbl... >a code sample would be nice. the columns is of a checkbox type. I want to prevent deselection after selection - EVEN if the selection was inadvertant. M 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 Show quoteHide quote "Mike" <none> wrote in message news:erePfQuIGHA.596@TK2MSFTNGP10.phx.gbl... > "Toff McGowen" <t*@toff.com> wrote in message > news:eaNRd7hIGHA.3700@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 > > 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 "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message There are grids and controls in VB6 that you can catch the mouse events on news:OG5uN2jIGHA.2300@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. 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 Fair enough, but that still won't prevent deselection of a selected > 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. checkbox. M 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?ID=bece831d-6742-4364-bd0d-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?ID=30d9d2fd-9f10-4928-b7c8-1def3152436f I hope this helps, Cor 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 ------------------- Show quoteHide quote "Mike" <none> wrote in message news:%23wocaChIGHA.532@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 > "Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message Thanks Ken,news:eli1y2mIGHA.216@TK2MSFTNGP15.phx.gbl... > Hi, > > You can always make the column read only. 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 |
|||||||||||||||||||||||