Best way to bind Controls to a DataGridCell


D

DraguVaso

Hi,

I foudn several ways to bind Controls to a DataGridCell, but I don't really
know which ways are the best.

The best solution for me would be that:
- I'm having one single way to bind all types of (DataBound)(User)Controls
- I can do all the stuff and parameters runtime (depending on other values
in my DataSource)
- easy and clear and fast

Anybody knows THE solution?

I found this one not too bad:

'Declare dynamic controls
Public WithEvents cc As New MonthCalendar()


Private Sub dgTest_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles dgTest.MouseUp
'Get size and location of grid cell
Dim cb As New System.Drawing.Rectangle() 'cell bounds

If dgTest.CurrentCell.ColumnNumber = 0 Then 'Column 0 clicked
If Not cc.Tag = "Open" Then 'Do once
'cc.Size = New Size(30, 30)
cb = dgTest.GetCellBounds(dgTest.CurrentRowIndex, 0) 'cell
bounds
cc.Location = New Point(cb.X, cb.Y) 'Location for month
control
dgTest.Controls.Add(cc) 'Add the month control
cc.Tag = "Open"
cc.BringToFront()
'must add the events you want to use
AddHandler cc.DateSelected, AddressOf cc_DateSelected
Else
'Same as above "without addhandler if control is already
open
cb = dgTest.GetCellBounds(dgTest.CurrentRowIndex, 0)
cc.Location = New Point(cb.X, cb.Y)
cc.BringToFront()
cc.Tag = "Open"
End If
cc.Show() 'Show the control
End If
End Sub


Private Sub cc_DateSelected(ByVal sender As Object, ByVal e As
System.Windows.Forms.DateRangeEventArgs) Handles cc.DateSelected
'Put selected date in selected cell then hide control
dgTest.Item(dgTest.CurrentRowIndex, 0) = cc.SelectionStart.Date
cc.Hide()
End Sub


Thanks in advance for your commentary/hints/help :)

Pieter
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top