Solved

datagrid checkbox colum lock

Posted on 2006-11-17
11
1,945 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
Comment Utility
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
Comment Utility
MICROCAOS,

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

Tim
0
 
LVL 13

Expert Comment

by:newyuppie
Comment Utility
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
 

Author Comment

by:MICROCAOS
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 13

Expert Comment

by:newyuppie
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
great
NY
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
Comment Utility
PAQd, 125 points refunded.

DarthMod
CS Moderator
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now