DataGrid/DataTable

J

JLong

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.
 
G

Guest

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

Chris, Master of All Things Insignificant

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
 
G

Guest

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
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top