By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,681 Members | 1,864 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,681 IT Pros & Developers. It's quick & easy.

DataGrid/DataTable

P: n/a
I am in pain here, so help please. I have a form with a
datagrid control to display a single datatable (created in
memory). I use the form's new sub to initialize the
datatable and set the schema and set the datagrid source,
so when the form is displayed you could see the table (no
datarows) it shows null in the first row. Now my problem
is once I collect the information I need to put in the
table. I use a procedure where I create a reference to
the datatable and add the datarows and finally reasign the
datasource of the datagrid using SetDataBinding() method,
but nothing is displyied. I am not using a dataset. I am
not sure if this is the way of doing this, so any
suggestions will be really appreciated.
Jul 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Not sure if I have all your info but have you done a .Refresh on the datagrid
after assignment?
Tom Y.

"JLong" wrote:
I am in pain here, so help please. I have a form with a
datagrid control to display a single datatable (created in
memory). I use the form's new sub to initialize the
datatable and set the schema and set the datagrid source,
so when the form is displayed you could see the table (no
datarows) it shows null in the first row. Now my problem
is once I collect the information I need to put in the
table. I use a procedure where I create a reference to
the datatable and add the datarows and finally reasign the
datasource of the datagrid using SetDataBinding() method,
but nothing is displyied. I am not using a dataset. I am
not sure if this is the way of doing this, so any
suggestions will be really appreciated.

Jul 21 '05 #2

P: n/a
Yes, I have tried that too :(
Jul 21 '05 #3

P: n/a
You shouldn't need to reassign the DataSource of the DataGrid. Can you
give us some code to further help you out? Are you sure the DataTable gets
the new rows?

Chris

"JLong" <an*******@discussions.microsoft.com> wrote in message
news:0f****************************@phx.gbl...
I am in pain here, so help please. I have a form with a
datagrid control to display a single datatable (created in
memory). I use the form's new sub to initialize the
datatable and set the schema and set the datagrid source,
so when the form is displayed you could see the table (no
datarows) it shows null in the first row. Now my problem
is once I collect the information I need to put in the
table. I use a procedure where I create a reference to
the datatable and add the datarows and finally reasign the
datasource of the datagrid using SetDataBinding() method,
but nothing is displyied. I am not using a dataset. I am
not sure if this is the way of doing this, so any
suggestions will be really appreciated.

Jul 21 '05 #4

P: n/a
Here is the function I am using.

Public Function AddData()
Dim cDataTable As DataTable
Dim Dcolumn As DataColumn
Dim cgrid As DataGrid
Dim myRow As DataRow
Dim I As Int16

cgrid = Me.grdInfo

cDataTable = cgrid.DataSource

For I = 0 To 5
myRow = cDataTable.NewRow()
myRow(0) = "Yes"
myRow(1) = "it"
myRow(2) = "should"
myRow(3) = "work"
cDataTable.Rows.Add(myRow)
Next I

cgrid.DataSource = cDataTable

End Function

Just note, the grid is displayed on the form and contains
the column structure as per the datatable. Here I am
trying to add data to the table. I have tryied printing
to the console the column colection and the rows and it
seems to be fine. However, I can't update the grid to
display the new added data. TIA
Jul 21 '05 #5

P: n/a
Well I think I just found what the problem is. See, the
datagrid is on a form which is a child of the a main
form. I use a dialogbox (a form) to alow the user to
select the file from which the data is to be collected.
The dialogbox is displayed by way of a manu on the main
form. Once the user select the files and click OK then
the function to collect and add the data to the table is
executed. That function is on the child form, the one with
the grid. When OK is clicked, I hide the dialogbox and
call the function. This seems to be the problem, because
if I execute the function by clicking on the child form,
it works fine. So, now I need to find a where to put the
function, how to execute it, and how to hide/close the
dialogbox.
Jul 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.