-
May 20th, 2010, 04:06 AM
#1
Thread Starter
Addicted Member
[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!
-
May 20th, 2010, 04:44 AM
#2
Re: adding textbox control in datagrid
DataGrid cells contain text boxes by default.
-
May 20th, 2010, 07:10 PM
#3
Thread Starter
Addicted Member
Re: adding textbox control in datagrid
Originally Posted by jmcilhinney
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
-
May 20th, 2010, 07:21 PM
#4
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.
-
May 20th, 2010, 07:34 PM
#5
Thread Starter
Addicted Member
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.
-
May 20th, 2010, 07:58 PM
#6
Thread Starter
Addicted Member
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?
-
May 20th, 2010, 08:04 PM
#7
Re: adding textbox control in datagrid
Originally Posted by [gja]
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.
-
May 20th, 2010, 08:07 PM
#8
Re: adding textbox control in datagrid
Originally Posted by [gja]
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?
-
May 20th, 2010, 08:45 PM
#9
Thread Starter
Addicted Member
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..
-
May 20th, 2010, 09:16 PM
#10
Re: adding textbox control in datagrid
Are you sure that you haven't set the grid's ReadOnly property to True?
-
May 21st, 2010, 01:27 AM
#11
Thread Starter
Addicted Member
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...
-
May 21st, 2010, 01:34 AM
#12
Re: adding textbox control in datagrid
Originally Posted by [gja]
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?
-
May 21st, 2010, 07:26 PM
#13
Thread Starter
Addicted Member
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..
-
May 22nd, 2010, 09:24 PM
#14
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
-
May 23rd, 2010, 06:56 PM
#15
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|