Solved

datagrid checkbox colum lock

Posted on 2006-11-17
11
1,952 Views
Last Modified: 2012-05-05
Hi all ..

This is my problem, i've got a datagrid with a checkbox column, but i only want to display check or unchecked from the database, i dont want the user to be able to change the status of the checkbox, it can only change when i let him ..

i've tryed using the readonly property but it does not suit me ..

Is there anything like on vb6

datagrid.column(index).locked = true or false ???
0
Comment
Question by:MICROCAOS
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 17963902
Hi MICROCAOS,

One solution is to add an onclick event handler with return false:

In your itemdatabound event, you can add attributes to each checkbox that is generated. Use:

MyCheckbox.Attributes.Add("onclick","return false;")

This will allow the checkbox to be displayed as normal, however any click will be discarded so the state will not be changed.

Tim Cottee
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 17963905
MICROCAOS,

Dopey me, that is an asp.net solution, not a vb.net solution. Hang on

Tim
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17963965
workaround could be if you handle the checkbox checkedchange event, you could add a code like:

checkbox1.checked = not chechbox1.checked

so that it will return the checked state to the one that was there before the click no matter if it was true or false.
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:MICROCAOS
ID: 17963985
no i cannot mess with the state of the check box .. it has a important value .. it has to display the corrected cheked state, the only thing i need is to disable the user from clicking on the checkbox in the datagrid so he cannot change te value unless i permit that in another form ...

TimCottee
eheheh i thought as mutch eheheh
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17964021
the code i posted will not mess with the checkbox state if you make these modifications:

1) declare a private variable for the class
private loading as boolean

2) in the form Load add this line at the very beginning of the load:
loading = true

3) and this to the very end of the sub
loading = false

3) handle the checkbox changed event with this code

If loading then Exit Sub
checkbox1.checked = not chechbox1.checked


this will
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17964035
this will allow you to load and set the datagrid source without handling the checkbox state. after load is done, if a user clicks on the checkbox, the handler will reclick it back to what it was originally.

also if you want to allow it programmatically from another form you could

1) add another variable to the class
public allowcheck as boolean

2) change the checkbox event handler to
If loading then Exit Sub
if not allowcheck then
  checkbox1.checked = not chechbox1.checked
end if

3) based on what you want to allow or not, switch the allowchecks to true of false from another form.


0
 

Author Comment

by:MICROCAOS
ID: 17964057
but .. how can i get to the event handler of the checkbox ???

BTW it's not a checkbox .. it's a DataGridBoolColumn on a datagrid and this is the code for it :

Dim dgEstiloColuna As New DataGridTableStyle
Dim colCheck As New DataGridBoolColumn

dgEstiloColuna.MappingName = dtsCOMPRAS.Tables("LINHAS").ToString

      colCheck.MappingName = "APP_GERCMP"
      colCheck.HeaderText = "Gerada"
      colCheck.AllowNull = False
      colCheck.TrueValue = True
      colCheck.FalseValue = False
      colCheck.ReadOnly = True
      colCheck.NullValue = False
      colCheck.Width = 50
      dgEstiloColuna.GridColumnStyles.Add(colCheck)

      grdAPP_ITMCMP.TableStyles.Add(dgEstiloColuna)

datagrid : grdAPP_ITMCMP
0
 

Author Comment

by:MICROCAOS
ID: 17964126
Ok i've found a solution :

Public Shared bolGRIDCHECKBOX As Boolean = True


colCheck.MappingName = "APP_GERCMP"
      colCheck.HeaderText = "Gerada"
      colCheck.AllowNull = False
      colCheck.TrueValue = True
      colCheck.FalseValue = False
      If bolGRIDCHECKBOX = True Then
         colCheck.ReadOnly = True
      Else
         colCheck.ReadOnly = False
      End If
      colCheck.NullValue = False
      colCheck.Width = 50
      dgEstiloColuna.GridColumnStyles.Add(colCheck)


Private Sub grdAPP_ITMCMP_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles grdAPP_ITMCMP.MouseUp
      Dim shtCHKCOL As Short = 10     'coluna checkbox
      Dim hti As DataGrid.HitTestInfo = Me.grdAPP_ITMCMP.HitTest(e.X, e.Y)

      Try
         If hti.Type = DataGrid.HitTestType.Cell AndAlso hti.Column = shtCHKCOL Then
            If bolGRIDCHECKBOX = False Then
               Me.grdAPP_ITMCMP(hti.Row, hti.Column) = Not CBool(Me.grdAPP_ITMCMP(hti.Row, hti.Column))
            End If
         End If
      Catch ex As Exception
         MessageBox.Show(ex.ToString())
      End Try

   End Sub


A it was so simple that i thought i couldn't work .. but .. it did eheh but thanks anyway ..
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17964628
great
NY
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 17988444
PAQd, 125 points refunded.

DarthMod
CS Moderator
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question