-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: Siva Chandran P
Message 6 in Discussion

Hi Shri,
 The following code provide desired the functionality. According to the control 
type which we specified, it will show the desired control in the datagrid.


Public Class DataGridDemo
    Inherits System.Windows.Forms.Form

    Private Const CTRL_TYPE_LABEL = 0
    Private Const CTRL_TYPE_EDIT = 1
    Private Const CTRL_TYPE_CHECKBOX = 2
    Private Const CTRL_TYPE_COMBOBOX = 3


    Private ctrlsEditor As Control() = {New Label, New TextBox, New CheckBox, 
New ComboBox}
    Private colCtrlType As New Collections.Specialized.NameValueCollection


#Region " Windows Form Designer generated code "
.....
#End Region

    Private Sub DataGridDemo_Load(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles MyBase.Load
        Dim dt As New Data.DataTable("Properties")
        Dim dr As Data.DataRow
        Dim chkBox As CheckBox

        dt.Columns.Add("Name")
        dt.Columns.Add("Value")

        dr = dt.NewRow
        dr.Item("Name") = "Name"
        dr.Item("Value") = vbNullString
        colCtrlType.Add("Name", CStr(CTRL_TYPE_LABEL))
        dt.Rows.Add(dr)
        dg.DataSource = dt.DefaultView

        dr = dt.NewRow
        dr.Item("Name") = "Text"
        dr.Item("Value") = vbNullString
        colCtrlType.Add("Text", CStr(CTRL_TYPE_EDIT))
        dt.Rows.Add(dr)
        dg.DataSource = dt.DefaultView

        dr = dt.NewRow
        dr.Item("Name") = "Enabled"
        dr.Item("Value") = 0
        colCtrlType.Add("Enabled", CStr(CTRL_TYPE_CHECKBOX))
        dt.Rows.Add(dr)
        dg.DataSource = dt.DefaultView

        dr = dt.NewRow
        dr.Item("Name") = "Style"
        dr.Item("Value") = New String() {"Flat", "Raised", "Sunken"}
        colCtrlType.Add("Style", CStr(CTRL_TYPE_COMBOBOX))
        dt.Rows.Add(dr)

        dg.DataSource = dt.DefaultView
        dg.ReadOnly = True

        CType(ctrlsEditor(CTRL_TYPE_CHECKBOX), CheckBox).CheckAlign = 
ContentAlignment.MiddleCenter

        For Each ctrl As Control In ctrlsEditor
            dg.Controls.Add(ctrl)
            ctrl.Visible = False
        Next

    End Sub

    Private Sub dg_CurrentCellChanged(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles dg.CurrentCellChanged

        Dim ctrlType As Integer
        Dim rectBound As Rectangle

        For Each ctrl As Control In ctrlsEditor
            ctrl.Visible = False
        Next

        ctrlType = CInt(colCtrlType.Get(dg.Item(dg.CurrentCell.RowNumber, 0)))

        rectBound = dg.GetCellBounds(dg.CurrentCell.RowNumber, 1)
        ctrlsEditor(ctrlType).SetBounds(rectBound.X, rectBound.Y, 
rectBound.Width, rectBound.Height)
        ctrlsEditor(ctrlType).Visible = True

    End Sub

End Class

Regards,
Shiva

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/BDOTNET/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member 
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you 
received this message by mistake, please click the "Remove" link below. On the 
pre-addressed e-mail message that opens, simply click "Send". Your e-mail 
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to