We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Changing the Grids Datasource

Clay, I am trying to change my grids datasource with no success: here is my code: Me.GridDataBoundResults.DataSource = Nothing Me.GridDataBoundResults.BeginUpdate() Me.GridDataBoundResults.Binder.SuspendBinding() Me.GridDataBoundResults.SuspendLayout() Me.GridDataBoundResults.Model.SuspendChangeEvents() Me.GridDataBoundResults.GridBoundColumns.Clear() Me.GridDataBoundResults.Binder.ResetHierarchyLevels() ''Code to add columns I want to see in the grid ... ... ... ''End add columns Me.GridDataBoundResults.DataSource = Me.BusinessObject.Results Me.GridDataBoundResults.Model.ResumeChangeEvents() Me.GridDataBoundResults.ResumeLayout() Me.GridDataBoundResults.Binder.ResumeBinding() Me.GridDataBoundResults.EndUpdate() When the code above executes the Grid will repaint the columns but none of the rows will show up. I have verified that the datatable (Me.BusinessObject.Results) has 51 rows. Also, just wanted to let you know that I sumbitted Direct Trac on Friday and the answer that was supplied cause a runtime error. I need a solution to this problem ASAP and that is why I am reposting into this forum. Thanks, Rob

6 Replies

AD Administrator Syncfusion Team January 26, 2004 10:47 AM UTC

The code below worked for me in this sample. Me.GridDataBoundGrid1.BeginUpdate() Me.GridDataBoundGrid1.DataSource = Nothing Me.GridDataBoundGrid1.GridBoundColumns.Clear() Me.GridDataBoundGrid1.Binder.ResetHierarchyLevels() Dim r As New Random() Dim dc As DataColumn For Each dc In dt.Columns Dim gbc As New GridBoundColumn() gbc.MappingName = dc.ColumnName gbc.StyleInfo.BackColor = Color.FromArgb(r.Next(256), r.Next(256), r.Next(256)) Me.GridDataBoundGrid1.GridBoundColumns.Add(gbc) Next Me.GridDataBoundGrid1.DataSource = dt Me.GridDataBoundGrid1.EndUpdate() Me.GridDataBoundGrid1.Refresh()


AD Administrator Syncfusion Team January 26, 2004 03:50 PM UTC

Clay, I''m calling the same code and the grid will not repaint the rows until I double click one of the column headers (row 0). I am going to keep looking .... any other ideas or pointers. Rob


AD Administrator Syncfusion Team January 26, 2004 04:31 PM UTC

Clay, I found thge problem. In your example, method GetATable(), instead of recreating the datatable everytime: Dim dt As New DataTable("MyTable" + tableNo.ToString()) Change to use a private variable: me.dt.clear() me.dt.reset() Then you will see the grid will not refresh. Rob


AD Administrator Syncfusion Team January 26, 2004 04:34 PM UTC

I assume the sample works OK, correct? Where are you trying to do this code? Does the grid have focus when you are doing it? (Normally, this does not matter, but if things are not working, then ???) You can try things like: Me.ActiveControl = grid ''if you are on a form grid.Focus()


AD Administrator Syncfusion Team January 26, 2004 04:46 PM UTC

Clay, If you change your sample to reuse the datatable, dt.clear() dt.reset(), you will see the same behaviour. Don''t create the datatable everytime .... create it in your form load. Since I am pretty much a newbie to DT''s I''m not 100% sure if I should reuse them or just create a new one everytime. In my instance I have a query window with the results being a datatable ... I thought I could essentially clear all the columns and rows and resuse the object ... but the grid doesn''t like that. Rob


AD Administrator Syncfusion Team January 26, 2004 08:04 PM UTC

If you want to reuse the datatable, then I think you will have to remove the rows and then the columns. Here is the sample modified to do this. forum_SwitchDS-2_6182.zip

Loader.
Live Chat Icon For mobile
Up arrow icon