473,385 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

add handlers to textboxes in a datagrid

sorry for so many posts recently

i am loading a datagrid from a datatable. the shape of the datatable is not
known at design time. i want to dynamically add event handlers to the
datagrid textboxes. it would be really easy if i were using a
DataGridTableStyle at design time but that means i know the columns.

how do i loop through the textboxes in the datagrid? i will have to do this
after i've used the setDataBinding method of the datagrid. that's the only
way how i will know how many columns (DataGridTextBoxColumn) there are.

for each x as DataGridTextBoxColumn in dgOrders.< ? >
AddHandler x.TextBox.MouseDown, New MouseEventHandler(AddressOf
someMouseDownEvent)
AddHandler x.TextBox.DoubleClick, New EventHandler(AddressOf
someDoubleClickEvent)
next
Nov 20 '05 #1
4 3026
Josh,

i am loading a datagrid from a datatable. the shape of the datatable is not known at design time.


When the shape of the datasource is not known at runtime you have no
datagrid at runtime as well, so what do you mean with that sentense?.

However when you want to do something with an event in a databox from a
datagrid, mayby you can than use this sample that I once made?

Cor

\\\
Private WithEvents dtbCol1 As DataGridTextBox
Private ToolTip1 As New ToolTip
')
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Datagrid1.ReadOnly = True
Dim ts As New DataGridTableStyle
ts.MappingName = ds.Tables(0).TableName
Dim column As New DataGridTextBoxColumn
ts.GridColumnStyles.Add(column)
DataGrid1.TableStyles.Add(ts)
column = DirectCast(ts.GridColumnStyles(0), DataGridTextBoxColumn)
dtbCol1 = DirectCast(column.TextBox, DataGridTextBox)
column.MappingName = ds.Tables(0).Columns(0).ColumnName
column.HeaderText = "Cor"
column.Width = 30
dv = New DataView(ds.Tables(0))
dv.AllowNew = False
DataGrid1.DataSource = dv
End Sub
Private Sub dtbCol1_ToolTip(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles dtbCol1.MouseEnter
ToolTip1.SetToolTip(DirectCast(sender, DataGridTextBox), _
"Row: " & DataGrid1.CurrentRowIndex + 1)
End Sub
///

Nov 20 '05 #2
I am not sure how you can load the grid and not know the column count. Are you loading the grtid with a dataset? If so see this example.

http://www.wizkil-webs.net/NET/DotNE...m#_Toc76871990

If not I agree with Cor.

B

"Josh Golden" wrote:
sorry for so many posts recently

i am loading a datagrid from a datatable. the shape of the datatable is not
known at design time. i want to dynamically add event handlers to the
datagrid textboxes. it would be really easy if i were using a
DataGridTableStyle at design time but that means i know the columns.

how do i loop through the textboxes in the datagrid? i will have to do this
after i've used the setDataBinding method of the datagrid. that's the only
way how i will know how many columns (DataGridTextBoxColumn) there are.

for each x as DataGridTextBoxColumn in dgOrders.< ? >
AddHandler x.TextBox.MouseDown, New MouseEventHandler(AddressOf
someMouseDownEvent)
AddHandler x.TextBox.DoubleClick, New EventHandler(AddressOf
someDoubleClickEvent)
next

Nov 20 '05 #3
Hi Brian,

A dataset is a collection of datatables, where ever you get them, it has to
be there at runtame to be usable with a datagrid. (And the runtime moment is
the moment it is connected as a datasource to the datagrid).
..
A datagrid has always a datasource whatever it is or it has no rows and no
cells.

So why do you not agree with me?

Cor

I am not sure how you can load the grid and not know the column count. Are you loading the grtid with a dataset? If so see this example.
http://www.wizkil-webs.net/NET/DotNE...m#_Toc76871990

If not I agree with Cor.

Nov 20 '05 #4
I know that.. and I did agree with you

B

"Cor Ligthert" wrote:
Hi Brian,

A dataset is a collection of datatables, where ever you get them, it has to
be there at runtame to be usable with a datagrid. (And the runtime moment is
the moment it is connected as a datasource to the datagrid).
..
A datagrid has always a datasource whatever it is or it has no rows and no
cells.

So why do you not agree with me?

Cor

I am not sure how you can load the grid and not know the column count.

Are you loading the grtid with a dataset? If so see this example.

http://www.wizkil-webs.net/NET/DotNE...m#_Toc76871990

If not I agree with Cor.


Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dave Cousineau | last post by:
im using VB.NET and i am creating an array of textboxes i want to handle a LostFocus event for any of the textboxes that i might create (at runtime), so that when the user enters a value into...
1
by: Pavel Gusak | last post by:
Hello. I've found DataGrid built-in edit functionality useless. My DataGrid has 9 columns, and is shown just nice until I press 'Edit' on a row. ASP.NET creates 9 TextBoxes, all the same very big...
0
by: Hai Nguyen | last post by:
Below is my code, would anybody please figure out why it did not display any thing. The database did not anything in there yet, what it does is the header field. It just shows me the headers only,...
1
by: mg | last post by:
How can I apply validation for date and currency on the values typed in EditItemTemplate TextBoxes in a DataGrid (C# WebForm)
12
by: Mike | last post by:
I'm calling a component to get my data. The component is returning a dataset. I need to populate text boxes on my aspx page with the data within the datalist. Where can I find an example that...
1
by: Arjen Hoekstra | last post by:
Hello, I've got a datagrid with a textbox in each cell. I've also two buttons, one to add a row to the datagrid and one to delete a row. A user can type data into textboxes and then submit it to...
2
by: nate axtell | last post by:
After binding a DataGrid and a few TextBoxes to the same DataTable in VB ..NET I successfully see the TextBoxes update when I change the selection in the DataGrid. I put DataGrid1.Invalidate() in...
5
by: rn5a | last post by:
Consider the following user control which resides in Address.ascx: <script runat="server"> Public Property Address() As String Get Address = txtAddress.Text End Get Set(ByVal value As String)...
5
by: Kolags | last post by:
Hi all, Please give me guidance to complete this task. As per my requirement, I want to place data in to different textboxes whatever I selected from datagrid using edit command name. Means I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.