• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 158
  • Last Modified:

Data Grid problem

Hello experts:

I need disable a first column of a datagrid. any ideas.

Thanks

Mario
0
Mario_castro
Asked:
Mario_castro
  • 4
  • 4
1 Solution
 
rrbeckerCommented:
Hi Mario,

One way to do it is to use the 'Custom' Properites or 'Layout' manager ( depending on the data control that you are using) and Define a layout that only displays the fields that you are interested in. You would just leave out the "...first column..." making it in-accessable.

rrbecker
0
 
RonaldBiemansCommented:
to you want to hide it or disable the textbox in the column
0
 
RonaldBiemansCommented:
to hide it, do something like this

        Dim ts As New DataGridTableStyle
        ts.MappingName = dt.TableName

        Dim dgtbc As New DataGridTextBoxColumn
        dgtbc.MappingName = "id"
        dgtbc.Width = 0
        ts.GridColumnStyles.Add(dgtbc)
        Me.DataGrid1.TableStyles.Add(ts)

to make it readonly

        Dim ts As New DataGridTableStyle
        ts.MappingName = dt.TableName

        Dim dgtbc As New DataGridTextBoxColumn
        dgtbc.MappingName = "id"
        dgtbc.readonly = true
        ts.GridColumnStyles.Add(dgtbc)
        Me.DataGrid1.TableStyles.Add(ts)

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Mario_castroAuthor Commented:
textbox
0
 
Mario_castroAuthor Commented:
but who is dt?
0
 
RonaldBiemansCommented:
Dt is the name of the table that is bound to the datagrid

you could also do it ilke

ds.tables(0).tablename
0
 
Mario_castroAuthor Commented:
ok this is the procedure but this code hide all datagrid!!!

  m_DataAdapter = New OleDbDataAdapter( _
        "SELECT id_cliente,Nombre,Apellidos,Fecha_Nacimiento,Genero,ins_educativa,Identificacion,Direccion,Ciudad,Telefono,Celular,Email FROM persona ORDER BY id_cliente", _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & oConn.GetDataFile("Data\\Capture_db.mdb"))
        m_DataSet.Clear()
        ' Fill the DataSet.
        m_DataAdapter.Fill(m_DataSet)

        ' Bind the DataGrid to the DataSet's first DataTable.
        DataGrid2.ResetText()
        DataGrid2.DataSource = m_DataSet.Tables(0)

        'disabled first column
        Dim ts As New DataGridTableStyle
        ts.MappingName = m_DataSet.Tables(0).TableName

        Dim dgtbc As New DataGridTextBoxColumn
        dgtbc.MappingName = "id"
        dgtbc.ReadOnly = True
        ts.GridColumnStyles.Add(dgtbc)
        Me.DataGrid2.TableStyles.Add(ts)
0
 
Mario_castroAuthor Commented:
this is the solution!.
 
Dim ts As DataGridTableStyle
        ts = New DataGridTableStyle
        ts.MappingName = m_DataSet.Tables(0).ToString()
        DataGrid2.TableStyles.Add(ts)
        DataGrid2.TableStyles(0).GridColumnStyles.Item(0).Width = 0
0
 
RonaldBiemansCommented:
my code was an example on how to do it, you still had to adjust it to fit your table
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now