Found the following interesting discussion in the Newsgroups:
| add handlers to textboxes in a datagrid by:Josh Golden | |
| 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: by:Cor Ligthert | |
| Josh, not 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: by:Anonymous | |
| 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/DotNET_Code_Samples.htm#_Toc76871990 If not I agree with Cor. B | |
| Reply: by:Cor Ligthert | |
| 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 Are you loading the grtid with a dataset? If so see this example. | |
| Reply: by:Anonymous | |
| I know that.. and I did agree with you B | |
Posted by Xander Zelders

0 Comments:
Post a Comment
<< Home