Need help with vb.net and datagrid

R

Roel

I need help to format the column and detect any change on the datagrid.

My source code is:

dim da as SqlDataAdapter
dim ds as DataSet
dim dtSource as DataTable

dim conn as SQLConnection = New SQLConnection(......)

da = New SQLDataAdapter ("Select field1, field2, from tablename",conn)
ds = New dataset

da.fill(ds,"tablename")

dtSource = ds.Tables("tablename")

datagrid1.datasource = dtsource


'===== So far everything up to this point is ok.
I try changing the column with for field 1 by using
PreferredColumnWidth but it doesn't work.

I can changed the datagrid but it wont update the table. How can I
detect if there is a new update so I can run datagrid1.update

Appreciate any help.

Thanks
Roel
 
C

Cor Ligthert [MVP]

Roel,

You can visit our website and search for "styles" than you get a lot of
samples

http://www.windowsformsdatagridhelp.com/default.aspx

If the solution for your problem is not there, than let us know (using this
newsgroup or the newsgroup)
microsoft.public.dotnet.languages.vb
(In that is Ken as well active).

However, I hope that it helps direct.

Cor
 
R

Roel

Cor

Your website was a good source of information and I was able to figure
out what I need.

I found this code on you site but I couldn't make it work. This is
when the datagrid is loaded and you press the delete key on a row.


AddHandler ds.Tables(0).RowDeleting, New
DataRowChangeEventHandler(AddressOf Row_Deleting)
'AddHandler ds.Tables(0).RowDeleted, New
DataRowChangeEventHandler(AddressOf Row_Deleting)



Private Sub Row_Deleting(ByVal sender As Object, ByVal e As
DataRowChangeEventArgs)

If MessageBox.Show("Delete row? ", "",
MessageBoxButtons.OKCancel) = DialogResult.Cancel Then
e.Row.RejectChanges()
'ds.RejectChanges()
Else
'get the staff id
MsgBox(e.Row.ItemArray(0))

End If
End Sub

It doesn't matter if I click Ok or Cancel, the row is deleted from the
datagrid. How can I put it back on the datagrid with out reloading
everything?

Thanks for your help.
Roel
 

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