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.
Unfortunately, activation email could not send to your email. Please try again.

Changing the Grids Datasource

Thread ID:

Created:

Updated:

Platform:

Replies:

10185 Jan 26,2004 04:55 AM Jan 26,2004 03:04 PM Windows Forms 6
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On January 26, 2004 04:55 AM

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

Administrator [Syncfusion]
Replied On January 26, 2004 05:47 AM

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()

Administrator [Syncfusion]
Replied On January 26, 2004 10:50 AM

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

Administrator [Syncfusion]
Replied On January 26, 2004 11:31 AM

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

Administrator [Syncfusion]
Replied On January 26, 2004 11:34 AM

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()

Administrator [Syncfusion]
Replied On January 26, 2004 11:46 AM

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

Administrator [Syncfusion]
Replied On January 26, 2004 03:04 PM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;