Solved

datagrid checkbox colum lock

Posted on 2006-11-17
11
1,957 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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