PC Review


Reply
Thread Tools Rate Thread

add handlers to textboxes in a datagrid

 
 
Josh Golden
Guest
Posts: n/a
 
      7th Jul 2004
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


 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      7th Jul 2004
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
///



 
Reply With Quote
 
=?Utf-8?B?QnJpYW5ESA==?=
Guest
Posts: n/a
 
      7th Jul 2004
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
>
>
>

 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      7th Jul 2004
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.
>



 
Reply With Quote
 
=?Utf-8?B?QnJpYW5ESA==?=
Guest
Posts: n/a
 
      7th Jul 2004
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.
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Datagrid with textboxes Eliyahu Goldin Microsoft ASP .NET 0 4th Jan 2007 09:52 AM
datagrid event handlers not being called in IIS 6 Edward Bills Microsoft ASP .NET 0 25th Aug 2004 08:01 PM
datagrid + textboxes John Microsoft VB .NET 2 12th Mar 2004 08:06 PM
textboxes in datagrid djozy Microsoft C# .NET 1 5th Jan 2004 08:28 PM
How can I do that: Datagrid and textboxes? [ F e r n a n d o L o p e s ] Microsoft Dot NET Framework Forms 0 20th Aug 2003 02:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:43 PM.