Results 1 to 15 of 15

Thread: [RESOLVED] adding textbox control in datagrid

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    Resolved [RESOLVED] adding textbox control in datagrid

    Hello There,
    I really need help here,i dont know how to add text box control in datagrid
    i have 5 column in a datagrid and i would like to put a textbox each column..how can i achieve this?..please...if you have a link there or any helpfull document please post it here ...

    thank you very much!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: adding textbox control in datagrid

    DataGrid cells contain text boxes by default.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    Re: adding textbox control in datagrid

    Quote Originally Posted by jmcilhinney View Post
    DataGrid cells contain text boxes by default.
    Hi JM,
    are u sure that it already have textbox on it?..im using vb 2003..

    thanks.
    glen

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: adding textbox control in datagrid

    I don't have VS.NET 2003 installed but I just used the following code to test a DataGrid:
    Code:
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, _
                               ByVal e As System.EventArgs) Handles MyBase.Load
            Dim grid As New DataGrid
    
            grid.Dock = DockStyle.Fill
            Me.Controls.Add(grid)
    
            Dim table As New DataTable
    
            With table.Columns
                .Add("ID", GetType(Integer))
                .Add("Name", GetType(String))
            End With
    
            With table.Rows
                .Add(1, "Peter")
                .Add(2, "Paul")
                .Add(3, "Mary")
            End With
    
            grid.DataSource = table
        End Sub
    
    End Class
    and sure enough, each cell was a text box cell.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    Re: adding textbox control in datagrid

    Thank you for quick reply JM,

    i will try this one right now,ill post back here if it works..thanks.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    Re: adding textbox control in datagrid

    Hello JM,

    Your code is only displaying data..and it fails somewhere in this line:
    With table.Rows
    .Add(1, "Peter") --- it needs a datarow parameter
    .Add(2, "Paul")
    .Add(3, "Mary")
    End With

    how can i create a textbox control when i click every cells on the datagrid?

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: adding textbox control in datagrid

    Quote Originally Posted by [gja] View Post
    Hello JM,

    Your code is only displaying data..and it fails somewhere in this line:
    With table.Rows
    .Add(1, "Peter") --- it needs a datarow parameter
    .Add(2, "Paul")
    .Add(3, "Mary")
    End With

    how can i create a textbox control when i click every cells on the datagrid?
    You don't need to keep asking the same question over and over, especially when you already have the answer and especially when that answer is that you don't have to do anything because what you want is the default behaviour. The fact that my example code to populate a DataTable isn't valid in VB.NET 2003 has absolutely no bearing on the DataGrid. I would assume that you already have a DataTable, so why can't you use that? If you do want to use my code then, to make it work in 2003, you'll have to change the part that adds the rows to this:
    Code:
            With table.Rows
                .Add(New Object() {1, "Peter"})
                .Add(New Object() {2, "Paul"})
                .Add(New Object() {3, "Mary"})
            End With
    That Add method was changed to support a ParamArray in .NET 2.0, but you must use an explicit array in earlier versions.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: adding textbox control in datagrid

    Quote Originally Posted by [gja] View Post
    Hello JM,

    Your code is only displaying data..and it fails somewhere in this line:
    With table.Rows
    .Add(1, "Peter") --- it needs a datarow parameter
    .Add(2, "Paul")
    .Add(3, "Mary")
    End With

    how can i create a textbox control when i click every cells on the datagrid?
    Now that I read this again, I'm confused. You say that it is displaying data but the code fails. How can it do both? If the code fails then how can the data be displayed?

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    Re: adding textbox control in datagrid

    sorry Jm,

    i changed that part..i declare a datarow and add a value..il asked that question again..if you a any comment or just want to see how you modify your code...but thank you anyway jm..

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: adding textbox control in datagrid

    Are you sure that you haven't set the grid's ReadOnly property to True?

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    Re: adding textbox control in datagrid

    Yes,i set it to True..because i just think of adding a textbox control on every cell i click in datagrid...

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: adding textbox control in datagrid

    Quote Originally Posted by [gja] View Post
    Yes,i set it to True..because i just think of adding a textbox control on every cell i click in datagrid...
    And you didn't think that that was worth mentioning earlier? What exactly are you hoping to achieve by setting ReadOnly to True and embedding your own TextBoxes over what the standard behaviour provides?

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    Re: adding textbox control in datagrid

    sorry again jm, i mess up here..

    i come up that decission to embed textbox control on datagrid because i need to use some events of a textbox like textchanged event,keypress..and maybe i can benefit some other events of textbox control in the future if there's maybe some changes in the specs..

  14. #14
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: adding textbox control in datagrid

    Here might be a useful place to start learning how the DataGrid works:

    http://forums.devx.com/showthread.php?t=99401

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    Re: adding textbox control in datagrid

    thank you very Jm for this helpfull link..

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