Search code examples
vb.netwinformsdatagrid

Enable or disable datagrid cell value


I have a datagrid please note its data grid not data grid view.

And this datagrid have

Column A with some String values

And

Column B With Datagridboolcolum(checkbook type)

What I need to achieve is disable or enable the checkbook of Column B based on some conditions

In datagridview its little easy but how will we implement it in datagrid?

My datagrid is populated using datasource


Solution

  • I resolved the issue in the following way.

    I added one event CurrentCellChanged like below

    Private Sub dgMyGrid_currentCellChanged(ByVal sender As Object, ByVal e as eventArgs) handles dgMygrid.currentcellchanged
    Dim rowNum As Integer=dgmygrid.currentcell.rownumber
    Dim column As Integer  = dgmygrid.currentcell.columnnumber
    Dim dgselectedcolum As datagridcolumnstyle = dgmygrid.tablestyles(mytablename).gridcolumnstyles(colnum)
    
    
    If dgMygrid.mappimgname.equals(mycolumnname) andalso dgmygrid.beginedit()
    
    Dim dataview As dataview =ctype(dgmygrid.datasource,dataview)
    
    If mycondition
        Dgselectedcolumn.readonly=true
    Else
        Dgselectedcolum.readonly =false
    
    Dgmygrid.endedit(dgselectedcolumn, rownum, false)