|
-
May 9th, 2003, 06:03 AM
#1
Thread Starter
Registered User
Problem with DataGrid. [Resolved]
I have a datagrid.
For example, my current cell has a text "good".
How can I retrieve the current cell value?
After I change the current cell's text to let say "bad", it will suppose automatically update the database, right? But it don't.
Why? Or do we need to add code to update the database on every changes?
Another problem is, what is the event for DataGrid which will be executed when we changed the text of a cell?
For example, when we change the current cell's text from "good" to "bad", which event is executed?
Please guide me. Can anyone provide me with code for me to refer easily?
Thank you.
Last edited by albertlse; Aug 21st, 2003 at 08:28 PM.
-
May 9th, 2003, 10:59 AM
#2
Frenzied Member
1- To retrive the current cell value:
VB Code:
myDatagrid(myDatagrid.CurrentCell)
2- There is an event called CurrentCell changed that fires only if you change the current cell and navigate to another cell. So if you wan to have the real time control over the cell being changed you have to build a custom datagridtextboxcolumn and override its textbox cchange event.
3- The datagrid updates its underlying datasource. If its a table in the dataset the database is not updated unless you update it using your dataset.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
May 11th, 2003, 07:06 PM
#3
Addicted Member
How can we access the events of TextBox which is defined in DataGrid Columns ?
Thanks
-
May 12th, 2003, 05:32 AM
#4
Thread Starter
Registered User
Lunatic3,
Can you show me how to add Textbox to a column in DataGrid?
I try to code, but fail.
Please show me the code / ways to do it. Thank you!
-
May 12th, 2003, 06:59 AM
#5
Frenzied Member
Can you show me how to add Textbox to a column in DataGrid?
I was not talking about adding a textbox to a column. I was talking about building your ouwn DatagridTextboxColumn:
Here is the code:
In a class:
VB Code:
Public Class myDGTXT
Inherits DataGridTextBoxColumn
Public Sub New()
MyBase.New()
AddHandler Me.TextBox.KeyPress, New System.Windows.Forms.KeyPressEventHandler(AddressOf HandleKeyPress)
' You can add handler for any of the events of the textbox you desire.
End Sub
Private Sub HandleKeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
'Some code
End Sub
End Class
and in your form it goes some thing like these:
Here we assume you have:
A datagrid called myDatagrid
A dataset called myDataset that contains a table called myTable
Now we add one custom DatagridTextboxColumn to it.
VB Code:
Dim ts as New DatagridTableStyle
Dim Dgtextclm as New myDGTXT
ts.MappingName = mydataset.mytable.TableName ' The Table of the dataset you want to bind to
Dgtextclm.MappingName =mydataset.mytable.Columns(0).ColumnName ' Binds the column to the coulmn 0 of your table
' Here you can set other properties like width, header text and so on
ts.GridColumnStyles.Add(Dgtextclm)
myDatagrid.TableStyles.Add(ts)
myDatagrid.Datasource=myDataset.myTable
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
May 13th, 2003, 07:44 AM
#6
Addicted Member
Thanks Lunatic3
It is working fine.
My objective is to access the TextChanged event of TextBox of DataGrid's Column. I tried but unable to find how ?
What I do in your example for TextBox_TextChanged event at "?"
=========
AddHandler Me.TextBox.TextChanged, New ? (AddressOf HandleKeyPress)
=========
and
=========
Private Sub HandleKeyPress(ByVal sender As Object, ByVal e As ? )
=========
Thanks
-
May 13th, 2003, 08:39 AM
#7
Frenzied Member
In your case it would be:
VB Code:
AddHandler Me.TextBox.TextChanged, New System.EventHandler(AddressOf handletextchange)
'Alternatively you can shorten it in this way:
'Me.TextBox.TextChanged, Addressof handletextchange
Private Sub handletextchange(ByVal sender As Object, ByVal e As System.EventArgs)
'some code
End Sub
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
May 13th, 2003, 01:54 PM
#8
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|