Results 1 to 8 of 8

Thread: Problem with DataGrid. [Resolved]

Hybrid View

  1. #1

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163

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

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    1- To retrive the current cell value:
    VB Code:
    1. 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

  3. #3
    Addicted Member parminder's Avatar
    Join Date
    Apr 2003
    Location
    India
    Posts
    168
    How can we access the events of TextBox which is defined in DataGrid Columns ?

    Thanks

  4. #4

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163

    Question

    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!

  5. #5
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    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:
    1. Public Class myDGTXT
    2.     Inherits DataGridTextBoxColumn
    3.     Public Sub New()
    4.         MyBase.New()
    5.         AddHandler Me.TextBox.KeyPress, New System.Windows.Forms.KeyPressEventHandler(AddressOf HandleKeyPress)
    6.        ' You can add handler for any of the events of the textbox you desire.
    7.     End Sub
    8.     Private Sub HandleKeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
    9.      'Some code
    10.     End Sub
    11. 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:
    1. Dim ts as New DatagridTableStyle
    2. Dim Dgtextclm as New myDGTXT
    3.  ts.MappingName = mydataset.mytable.TableName ' The Table of the dataset you want to bind to
    4. Dgtextclm.MappingName =mydataset.mytable.Columns(0).ColumnName ' Binds the column to the coulmn 0 of your table
    5. ' Here you can set other properties like width, header text and so on
    6. ts.GridColumnStyles.Add(Dgtextclm)
    7. myDatagrid.TableStyles.Add(ts)
    8. 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

  6. #6
    Addicted Member parminder's Avatar
    Join Date
    Apr 2003
    Location
    India
    Posts
    168
    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

  7. #7
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    In your case it would be:
    VB Code:
    1. AddHandler Me.TextBox.TextChanged, New System.EventHandler(AddressOf handletextchange)
    2. 'Alternatively you can shorten it in this way:
    3. 'Me.TextBox.TextChanged, Addressof handletextchange
    4. Private Sub handletextchange(ByVal sender As Object, ByVal e As System.EventArgs)
    5.   'some code
    6. 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

  8. #8
    Addicted Member parminder's Avatar
    Join Date
    Apr 2003
    Location
    India
    Posts
    168

    Talking

    Thanks Lunatic3,


    It is workng fine.

    Thanks once again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width