خرید بک لینک

Vote count: 0

What I need: when this given Form shows for the first time, it should to create a datatable and bind it to a DataGridView, on which I want the two first columns to be hidden.

Rows will be added to this table by another function, upon user selects an item in other control. User can then set some data using the DataGridView, which should reflect on bound DataTable

I've chosen to use a bound datatable because one of the columns stores data whose type is given from a custom classin my project, and I wanted the other columns to remain strongly typed too.

The problem: When it gets to hide the columns, I got "System.NullReferenceException" and then I could verify that DataGridView didn't contain any columns, even if its DataSource property was set to a DataTable which has columns, and AutoGenerateColumns property was set to true.

What is going wrong? Code below (.NET 4.5, Winforms)

Private dtItens as DataTable
Private Sub DataGridViewProcessos_ParentChanged(sender As Object, e As EventArgs) _
            Handles DataGridViewProcessos.ParentChanged
    If TableViewProcessos.DataSource Is Nothing Then
        dtItens = New DataTable
        dtItens.Columns.Add("pasta_id", GetType(Integer))
        dtItens.Columns.Add("proc_legacy", GetType(LegacyData.Proc))
        dtItens.Columns.Add("numero", GetType(String))
        dtItens.Columns.Add("volumes", GetType(Integer))
        dtItens.Columns.Add("apensamento", GetType(String))
        dtItens.Columns.Add("observacoes", GetType(String))
        DataGridViewProcessos.AutoGenerateColumns = True
        DataGridViewProcessos.DataSource = dtItens
    End If
End Sub
Private Sub DataGridViewProcessos_DataSourceChanged(sender As Object, e As EventArgs) _
            Handles DataGridViewProcessos.DataSourceChanged
    If TableViewProcessos.DataSource IsNot Nothing Then
        DataGridViewProcessos.Columns("pasta_id").Visible = False
        DataGridViewProcessos.Columns("proc_legacy").Visible = False
    End If
End Sub

asked 42 secs ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 6 خرداد 1395 ساعت: 6:41

صفحه بندی