locked
Update datagridview columns at runtime RRS feed

  • Question

  • Hi,

    I have a function where the user can set which columns in a datagrid to be visible. The datagrid is located in a tabcontrol.

    My problem is that the gridview wont get updated until the user switches tab. So i figure there must be some update function on the datagrid which is being run when it gets repainted on a new tab?

    I have tried update() and refresh() but those two only updates the data inside the grid.

    Any ideas on how i can make this update in runtime?

    Thanks in advance,
    JF
    • Moved by Zhi-Xin Ye Friday, July 18, 2008 5:50 AM I recommend posted this thread in Windows Forms forums for better responses.
    Monday, July 14, 2008 2:19 PM

Answers

  • The problem was that i tried to update a specific datagridview from another form without having created an instance of the parent window. Once that was made, the update was very simple :D


    Thanks for your replies,

    JF

    Johan Frisell
    • Marked as answer by Frisell Friday, August 15, 2008 12:45 PM
    Friday, August 15, 2008 12:45 PM

All replies

  • I can't reproduce that problem. I put a dataGridView on a tab control and connected it to an sql data source. I added a button for swithing the Visible property true and false for the first column. And it works without having to switch tabs.

    Perhaps you could post some of your code.

    thanks

    /Calle

    Tuesday, July 15, 2008 7:54 AM
  • Hi,

    Thanks for your answer and sorry for my late answer, been on vaccation :)

    I think the reason why your function works is that you use a datasource which is bound autmatically to the datagridview. While I have the datasource in my memory.

    I'll paste some sample code, and see if it helps.

     Dim view As New DataView 
            Dim strFilter As String 
            Dim blnFirst As Boolean = True 
     
     
            logContr = New ContrLOG_Log 
            view.Table = table 
            If newSettings = False Then 
                dsSettings = logContr.getViewSettings() 
            End If 
     
            If Not CType(dsSettings.Tables(0).Rows(0).Item(12), Boolean) = True Then 
                strFilter = "colHidden = False" 
                blnFirst = False 
            End If 
     
            If blnFirst Then 
                strFilter = "colTime >= #" & CType(dsSettings.Tables(0).Rows(0).Item(13), DateTime).ToShortDateString() & "#" 
            ElseIf Not blnFirst Then 
                strFilterstrFilter = strFilter & " AND colTime >= #" & CType(dsSettings.Tables(0).Rows(0).Item(13), DateTime).ToShortDateString() & "#" 
            End If 
     
            'Information 
            If dsSettings.Tables(0).Rows(0).Item(9) = False Then 
                strFilterstrFilter = strFilter & " AND colCategory <> 'information'" 
            End If 
     
            'Warning 
            If dsSettings.Tables(0).Rows(0).Item(10) = False Then 
                strFilterstrFilter = strFilter & " AND colCategory <> 'warning'" 
            End If 
     
            'Error 
            If dsSettings.Tables(0).Rows(0).Item(11) = False Then 
                strFilterstrFilter = strFilter & " AND colCategory <> 'error'" 
            End If 
     
            view.RowFilter = strFilter 
            gridLogs.DataSource = view 
     
            gridLogs.Columns("colHidden").Visible = False 
            gridLogs.Columns("colId").Visible = False 
            gridLogs.Columns("colCategory").Visible = False 
            gridLogs.Columns("colAlarm").Visible = False 
     
            gridLogs.Columns("colImgCategory").Visible = dsSettings.Tables(0).Rows(0).Item(0) 
            gridLogs.Columns("colImgAlarm").Visible = dsSettings.Tables(0).Rows(0).Item(4) 
            gridLogs.Columns("colTime").Visible = dsSettings.Tables(0).Rows(0).Item(1) 
            gridLogs.Columns("colDescription").Visible = dsSettings.Tables(0).Rows(0).Item(3) 
            gridLogs.Columns("colModule").Visible = dsSettings.Tables(0).Rows(0).Item(2) 
            gridLogs.Columns("colObject").Visible = dsSettings.Tables(0).Rows(0).Item(6) 
            gridLogs.Columns("colUser").Visible = dsSettings.Tables(0).Rows(0).Item(5) 
            gridLogs.Columns("colComputer").Visible = dsSettings.Tables(0).Rows(0).Item(7) 
            gridLogs.Columns("colApplication").Visible = dsSettings.Tables(0).Rows(0).Item(8) 

    • Edited by Frisell Monday, July 28, 2008 9:11 AM added code
    Monday, July 28, 2008 9:10 AM
  • The problem was that i tried to update a specific datagridview from another form without having created an instance of the parent window. Once that was made, the update was very simple :D


    Thanks for your replies,

    JF

    Johan Frisell
    • Marked as answer by Frisell Friday, August 15, 2008 12:45 PM
    Friday, August 15, 2008 12:45 PM