Let me brief you what exact i want to do with this code :
I am reading registry data (presently its hard coaded) and populating it in
the datatable which is bound to datagrid. user can update the registry data
in the grid and on click of save it should update the registry... which is
not happending.. datatable seems empty..
Thanks for your help
Imports System
Imports System.Data
Imports Microsoft.Win32
Imports System.Data.Sql Client
Public Class Configuration
Inherits System.Windows. Forms.Form
Private dataTable As System.Data.Dat aTable
Private maxColumnNumber As Integer
Private maxRowNumber As Integer
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents btnReadRegistry As System.Windows. Forms.Button
Friend WithEvents tvRegistry As System.Windows. Forms.TreeView
Friend WithEvents dtgRegistry As System.Windows. Forms.DataGrid
Friend WithEvents imglstConfigura tion As System.Windows. Forms.ImageList
Friend WithEvents btnCancel As System.Windows. Forms.Button
Friend WithEvents btnSave As System.Windows. Forms.Button
Friend WithEvents DataSetConfigur ation As System.Data.Dat aSet
Friend WithEvents SqlConnectionCo nfiguration As
System.Data.Sql Client.SqlConne ction
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
Me.components = New System.Componen tModel.Containe r()
Dim resources As System.Resource s.ResourceManag er = New
System.Resource s.ResourceManag er(GetType(Conf iguration))
Me.btnReadRegis try = New System.Windows. Forms.Button()
Me.tvRegistry = New System.Windows. Forms.TreeView( )
Me.imglstConfig uration = New System.Windows. Forms.ImageList (Me.components)
Me.dtgRegistry = New System.Windows. Forms.DataGrid( )
Me.btnCancel = New System.Windows. Forms.Button()
Me.btnSave = New System.Windows. Forms.Button()
Me.DataSetConfi guration = New System.Data.Dat aSet()
Me.SqlConnectio nConfiguration = New System.Data.Sql Client.SqlConne ction()
CType(Me.dtgReg istry, System.Componen tModel.ISupport Initialize).Beg inInit()
CType(Me.DataSe tConfiguration,
System.Componen tModel.ISupport Initialize).Beg inInit()
Me.SuspendLayou t()
'
'btnReadRegistr y
'
Me.btnReadRegis try.AccessibleD escription =
CType(resources .GetObject("btn ReadRegistry.Ac cessibleDescrip tion"), String)
Me.btnReadRegis try.AccessibleN ame =
CType(resources .GetObject("btn ReadRegistry.Ac cessibleName"), String)
Me.btnReadRegis try.Anchor =
CType(resources .GetObject("btn ReadRegistry.An chor"),
System.Windows. Forms.AnchorSty les)
Me.btnReadRegis try.BackgroundI mage =
CType(resources .GetObject("btn ReadRegistry.Ba ckgroundImage") ,
System.Drawing. Image)
Me.btnReadRegis try.Dock = CType(resources .GetObject("btn ReadRegistry.Do ck"),
System.Windows. Forms.DockStyle )
Me.btnReadRegis try.Enabled =
CType(resources .GetObject("btn ReadRegistry.En abled"), Boolean)
Me.btnReadRegis try.FlatStyle =
CType(resources .GetObject("btn ReadRegistry.Fl atStyle"),
System.Windows. Forms.FlatStyle )
Me.btnReadRegis try.Font = CType(resources .GetObject("btn ReadRegistry.Fo nt"),
System.Drawing. Font)
Me.btnReadRegis try.Image =
CType(resources .GetObject("btn ReadRegistry.Im age"), System.Drawing. Image)
Me.btnReadRegis try.ImageAlign =
CType(resources .GetObject("btn ReadRegistry.Im ageAlign"),
System.Drawing. ContentAlignmen t)
Me.btnReadRegis try.ImageIndex =
CType(resources .GetObject("btn ReadRegistry.Im ageIndex"), Integer)
Me.btnReadRegis try.ImeMode =
CType(resources .GetObject("btn ReadRegistry.Im eMode"),
System.Windows. Forms.ImeMode)
Me.btnReadRegis try.Location =
CType(resources .GetObject("btn ReadRegistry.Lo cation"), System.Drawing. Point)
Me.btnReadRegis try.Name = "btnReadRegistr y"
Me.btnReadRegis try.RightToLeft =
CType(resources .GetObject("btn ReadRegistry.Ri ghtToLeft"),
System.Windows. Forms.RightToLe ft)
Me.btnReadRegis try.Size = CType(resources .GetObject("btn ReadRegistry.Si ze"),
System.Drawing. Size)
Me.btnReadRegis try.TabIndex =
CType(resources .GetObject("btn ReadRegistry.Ta bIndex"), Integer)
Me.btnReadRegis try.Text = resources.GetSt ring("btnReadRe gistry.Text")
Me.btnReadRegis try.TextAlign =
CType(resources .GetObject("btn ReadRegistry.Te xtAlign"),
System.Drawing. ContentAlignmen t)
Me.btnReadRegis try.Visible =
CType(resources .GetObject("btn ReadRegistry.Vi sible"), Boolean)
'
'tvRegistry
'
Me.tvRegistry.A ccessibleDescri ption =
CType(resources .GetObject("tvR egistry.Accessi bleDescription" ), String)
Me.tvRegistry.A ccessibleName =
CType(resources .GetObject("tvR egistry.Accessi bleName"), String)
Me.tvRegistry.A nchor = CType(resources .GetObject("tvR egistry.Anchor" ),
System.Windows. Forms.AnchorSty les)
Me.tvRegistry.B ackColor = System.Drawing. SystemColors.Wi ndow
Me.tvRegistry.B ackgroundImage =
CType(resources .GetObject("tvR egistry.Backgro undImage"),
System.Drawing. Image)
Me.tvRegistry.D ock = CType(resources .GetObject("tvR egistry.Dock"),
System.Windows. Forms.DockStyle )
Me.tvRegistry.E nabled = CType(resources .GetObject("tvR egistry.Enabled "),
Boolean)
Me.tvRegistry.F ont = CType(resources .GetObject("tvR egistry.Font"),
System.Drawing. Font)
Me.tvRegistry.I mageIndex =
CType(resources .GetObject("tvR egistry.ImageIn dex"), Integer)
Me.tvRegistry.I mageList = Me.imglstConfig uration
Me.tvRegistry.I meMode = CType(resources .GetObject("tvR egistry.ImeMode "),
System.Windows. Forms.ImeMode)
Me.tvRegistry.I ndent = CType(resources .GetObject("tvR egistry.Indent" ),
Integer)
Me.tvRegistry.I temHeight =
CType(resources .GetObject("tvR egistry.ItemHei ght"), Integer)
Me.tvRegistry.L ocation = CType(resources .GetObject("tvR egistry.Locatio n"),
System.Drawing. Point)
Me.tvRegistry.N ame = "tvRegistry "
Me.tvRegistry.N odes.AddRange(N ew System.Windows. Forms.TreeNode( )
{CType(resource s.GetObject("tv Registry.Nodes. Nodes"),
System.Windows. Forms.TreeNode) })
Me.tvRegistry.R ightToLeft =
CType(resources .GetObject("tvR egistry.RightTo Left"),
System.Windows. Forms.RightToLe ft)
Me.tvRegistry.S electedImageInd ex =
CType(resources .GetObject("tvR egistry.Selecte dImageIndex"), Integer)
Me.tvRegistry.S ize = CType(resources .GetObject("tvR egistry.Size"),
System.Drawing. Size)
Me.tvRegistry.T abIndex = CType(resources .GetObject("tvR egistry.TabInde x"),
Integer)
Me.tvRegistry.T ext = resources.GetSt ring("tvRegistr y.Text")
Me.tvRegistry.V isible = CType(resources .GetObject("tvR egistry.Visible "),
Boolean)
'
'imglstConfigur ation
'
Me.imglstConfig uration.ColorDe pth =
System.Windows. Forms.ColorDept h.Depth8Bit
Me.imglstConfig uration.ImageSi ze =
CType(resources .GetObject("img lstConfiguratio n.ImageSize"),
System.Drawing. Size)
Me.imglstConfig uration.ImageSt ream =
CType(resources .GetObject("img lstConfiguratio n.ImageStream") ,
System.Windows. Forms.ImageList Streamer)
Me.imglstConfig uration.Transpa rentColor = System.Drawing. Color.Transpare nt
'
'dtgRegistry
'
Me.dtgRegistry. AccessibleDescr iption =
CType(resources .GetObject("dtg Registry.Access ibleDescription "), String)
Me.dtgRegistry. AccessibleName =
CType(resources .GetObject("dtg Registry.Access ibleName"), String)
Me.dtgRegistry. Anchor = CType(resources .GetObject("dtg Registry.Anchor "),
System.Windows. Forms.AnchorSty les)
Me.dtgRegistry. BackColor = System.Drawing. SystemColors.In fo
Me.dtgRegistry. BackgroundImage =
CType(resources .GetObject("dtg Registry.Backgr oundImage"),
System.Drawing. Image)
Me.dtgRegistry. CaptionFont = CType(resources .GetObject("dtg Registry.Captio nF
ont"), System.Drawing. Font)
Me.dtgRegistry. CaptionText = resources.GetSt ring("dtgRegist ry.CaptionText" )
Me.dtgRegistry. DataMember = ""
Me.dtgRegistry. Dock = CType(resources .GetObject("dtg Registry.Dock") ,
System.Windows. Forms.DockStyle )
Me.dtgRegistry. Enabled = CType(resources .GetObject("dtg Registry.Enable d"),
Boolean)
Me.dtgRegistry. Font = CType(resources .GetObject("dtg Registry.Font") ,
System.Drawing. Font)
Me.dtgRegistry. HeaderForeColor = System.Drawing. SystemColors.Co ntrolText
Me.dtgRegistry. ImeMode = CType(resources .GetObject("dtg Registry.ImeMod e"),
System.Windows. Forms.ImeMode)
Me.dtgRegistry. Location = CType(resources .GetObject("dtg Registry.Locati on"),
System.Drawing. Point)
Me.dtgRegistry. Name = "dtgRegistr y"
Me.dtgRegistry. RightToLeft =
CType(resources .GetObject("dtg Registry.RightT oLeft"),
System.Windows. Forms.RightToLe ft)
Me.dtgRegistry. Size = CType(resources .GetObject("dtg Registry.Size") ,
System.Drawing. Size)
Me.dtgRegistry. TabIndex = CType(resources .GetObject("dtg Registry.TabInd ex"),
Integer)
Me.dtgRegistry. Visible = CType(resources .GetObject("dtg Registry.Visibl e"),
Boolean)
'
'btnCancel
'
Me.btnCancel.Ac cessibleDescrip tion =
CType(resources .GetObject("btn Cancel.Accessib leDescription") , String)
Me.btnCancel.Ac cessibleName =
CType(resources .GetObject("btn Cancel.Accessib leName"), String)
Me.btnCancel.An chor = CType(resources .GetObject("btn Cancel.Anchor") ,
System.Windows. Forms.AnchorSty les)
Me.btnCancel.Ba ckgroundImage =
CType(resources .GetObject("btn Cancel.Backgrou ndImage"),
System.Drawing. Image)
Me.btnCancel.Do ck = CType(resources .GetObject("btn Cancel.Dock"),
System.Windows. Forms.DockStyle )
Me.btnCancel.En abled = CType(resources .GetObject("btn Cancel.Enabled" ),
Boolean)
Me.btnCancel.Fl atStyle = CType(resources .GetObject("btn Cancel.FlatStyl e"),
System.Windows. Forms.FlatStyle )
Me.btnCancel.Fo nt = CType(resources .GetObject("btn Cancel.Font"),
System.Drawing. Font)
Me.btnCancel.Im age = CType(resources .GetObject("btn Cancel.Image"),
System.Drawing. Image)
Me.btnCancel.Im ageAlign = CType(resources .GetObject("btn Cancel.ImageAli gn"),
System.Drawing. ContentAlignmen t)
Me.btnCancel.Im ageIndex = CType(resources .GetObject("btn Cancel.ImageInd ex"),
Integer)
Me.btnCancel.Im eMode = CType(resources .GetObject("btn Cancel.ImeMode" ),
System.Windows. Forms.ImeMode)
Me.btnCancel.Lo cation = CType(resources .GetObject("btn Cancel.Location "),
System.Drawing. Point)
Me.btnCancel.Na me = "btnCancel"
Me.btnCancel.Ri ghtToLeft =
CType(resources .GetObject("btn Cancel.RightToL eft"),
System.Windows. Forms.RightToLe ft)
Me.btnCancel.Si ze = CType(resources .GetObject("btn Cancel.Size"),
System.Drawing. Size)
Me.btnCancel.Ta bIndex = CType(resources .GetObject("btn Cancel.TabIndex "),
Integer)
Me.btnCancel.Te xt = resources.GetSt ring("btnCancel .Text")
Me.btnCancel.Te xtAlign = CType(resources .GetObject("btn Cancel.TextAlig n"),
System.Drawing. ContentAlignmen t)
Me.btnCancel.Vi sible = CType(resources .GetObject("btn Cancel.Visible" ),
Boolean)
'
'btnSave
'
Me.btnSave.Acce ssibleDescripti on =
CType(resources .GetObject("btn Save.Accessible Description"), String)
Me.btnSave.Acce ssibleName =
CType(resources .GetObject("btn Save.Accessible Name"), String)
Me.btnSave.Anch or = CType(resources .GetObject("btn Save.Anchor"),
System.Windows. Forms.AnchorSty les)
Me.btnSave.Back groundImage =
CType(resources .GetObject("btn Save.Background Image"), System.Drawing. Image)
Me.btnSave.Dock = CType(resources .GetObject("btn Save.Dock"),
System.Windows. Forms.DockStyle )
Me.btnSave.Enab led = CType(resources .GetObject("btn Save.Enabled"), Boolean)
Me.btnSave.Flat Style = CType(resources .GetObject("btn Save.FlatStyle" ),
System.Windows. Forms.FlatStyle )
Me.btnSave.Font = CType(resources .GetObject("btn Save.Font"),
System.Drawing. Font)
Me.btnSave.Imag e = CType(resources .GetObject("btn Save.Image"),
System.Drawing. Image)
Me.btnSave.Imag eAlign = CType(resources .GetObject("btn Save.ImageAlign "),
System.Drawing. ContentAlignmen t)
Me.btnSave.Imag eIndex = CType(resources .GetObject("btn Save.ImageIndex "),
Integer)
Me.btnSave.ImeM ode = CType(resources .GetObject("btn Save.ImeMode"),
System.Windows. Forms.ImeMode)
Me.btnSave.Loca tion = CType(resources .GetObject("btn Save.Location") ,
System.Drawing. Point)
Me.btnSave.Name = "btnSave"
Me.btnSave.Righ tToLeft = CType(resources .GetObject("btn Save.RightToLef t"),
System.Windows. Forms.RightToLe ft)
Me.btnSave.Size = CType(resources .GetObject("btn Save.Size"),
System.Drawing. Size)
Me.btnSave.TabI ndex = CType(resources .GetObject("btn Save.TabIndex") ,
Integer)
Me.btnSave.Text = resources.GetSt ring("btnSave.T ext")
Me.btnSave.Text Align = CType(resources .GetObject("btn Save.TextAlign" ),
System.Drawing. ContentAlignmen t)
Me.btnSave.Visi ble = CType(resources .GetObject("btn Save.Visible"), Boolean)
'
'DataSetConfigu ration
'
Me.DataSetConfi guration.DataSe tName = "ConfigurationD ataSet"
Me.DataSetConfi guration.Locale = New
System.Globaliz ation.CultureIn fo("en-US")
'
'Configuration
'
Me.AccessibleDe scription =
CType(resources .GetObject("$th is.AccessibleDe scription"), String)
Me.AccessibleNa me = CType(resources .GetObject("$th is.AccessibleNa me"),
String)
Me.Anchor = CType(resources .GetObject("$th is.Anchor"),
System.Windows. Forms.AnchorSty les)
Me.AutoScaleBas eSize = CType(resources .GetObject("$th is.AutoScaleBas eSize"),
System.Drawing. Size)
Me.AutoScroll = CType(resources .GetObject("$th is.AutoScroll") , Boolean)
Me.AutoScrollMa rgin = CType(resources .GetObject("$th is.AutoScrollMa rgin"),
System.Drawing. Size)
Me.AutoScrollMi nSize = CType(resources .GetObject("$th is.AutoScrollMi nSize"),
System.Drawing. Size)
Me.BackgroundIm age = CType(resources .GetObject("$th is.BackgroundIm age"),
System.Drawing. Image)
Me.ClientSize = CType(resources .GetObject("$th is.ClientSize") ,
System.Drawing. Size)
Me.Controls.Add Range(New System.Windows. Forms.Control() {Me.btnSave,
Me.btnCancel, Me.dtgRegistry, Me.tvRegistry, Me.btnReadRegis try})
Me.Dock = CType(resources .GetObject("$th is.Dock"),
System.Windows. Forms.DockStyle )
Me.Enabled = CType(resources .GetObject("$th is.Enabled"), Boolean)
Me.Font = CType(resources .GetObject("$th is.Font"), System.Drawing. Font)
Me.Icon = CType(resources .GetObject("$th is.Icon"), System.Drawing. Icon)
Me.ImeMode = CType(resources .GetObject("$th is.ImeMode"),
System.Windows. Forms.ImeMode)
Me.Location = CType(resources .GetObject("$th is.Location"),
System.Drawing. Point)
Me.MaximumSize = CType(resources .GetObject("$th is.MaximumSize" ),
System.Drawing. Size)
Me.MinimumSize = CType(resources .GetObject("$th is.MinimumSize" ),
System.Drawing. Size)
Me.Name = "Configurat ion"
Me.RightToLeft = CType(resources .GetObject("$th is.RightToLeft" ),
System.Windows. Forms.RightToLe ft)
Me.StartPositio n = CType(resources .GetObject("$th is.StartPositio n"),
System.Windows. Forms.FormStart Position)
Me.Text = resources.GetSt ring("$this.Tex t")
Me.Visible = CType(resources .GetObject("$th is.Visible"), Boolean)
CType(Me.dtgReg istry, System.Componen tModel.ISupport Initialize).End Init()
CType(Me.DataSe tConfiguration,
System.Componen tModel.ISupport Initialize).End Init()
Me.ResumeLayout (False)
End Sub
#End Region
Private cnnConfiguratio n As SqlConnection
Private daConfiguration As SqlDataAdapter
Private dsConfiguration As DataSet
Private drConfiguration As SqlDataReader
Private Sub Configuration_L oad(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Expand the tree view
tvRegistry.Expa ndAll()
End Sub
Private Sub InitializeTable ()
Dim index As Integer
Dim objRegKey As RegistryKey
Dim sKeyValue As String
objRegKey = Registry.LocalM achine.OpenSubK ey("Software\da tabase\emailinf o",
True)
sKeyValue = objRegKey.GetVa lue("FromName", "AAA")
' Create a DataTable named "Registry Data".
dataTable = New DataTable("Regi stryData")
' Create columns in the DataTable.
addColumns()
AddNewRow("Comp any", "REG_SZ", "OCS")
AddNewRow("Emai lID", "REG_SZ", "a@b.com")
AddNewRow("Erro rEmailID", "REG_SZ", "te************ @ocs.com")
AddNewRow("From Name", "REG_SZ", sKeyValue)
AddNewRow("Reci pientEmail", "REG_SZ", "fa******@aaa.c om")
AddNewRow("Rese ndInterval", "REG_DWORD" , "3e80")
AddNewRow("Rese ndLimit", "REG_DWORD" , "2")
AddNewRow("Send erEmail", "REG_SZ", "pd*****@aaa.co m")
AddNewRow("WebM aster", "REG_SZ", "Te************ @ocs.com")
End Sub
Private Sub addColumns()
dataTable.Colum ns.Add("Name", Type.GetType("S ystem.String"))
dataTable.Colum ns.Add("Type", Type.GetType("S ystem.String"))
dataTable.Colum ns.Add("Data", Type.GetType("S ystem.String"))
End Sub
Private Sub AddNewRow(ByVal StringName As String, ByVal StringType As
String, ByVal StringData As String)
Dim dataRow As DataRow
dataRow = dataTable.NewRo w()
dataRow(0) = StringName
dataRow(1) = StringType
dataRow(2) = StringData
dataTable.Rows. Add(dataRow)
End Sub
Private Sub tvRegistry_Afte rSelect(ByVal sender As System.Object, ByVal e As
System.Windows. Forms.TreeViewE ventArgs) Handles tvRegistry.Afte rSelect
Dim sSelectedNode As String = tvRegistry.Sele ctedNode.Text
dtgRegistry.Cap tionText = tvRegistry.Sele ctedNode.FullPa th
If StrComp(UCase(s SelectedNode), "EMAILINFO" , CompareMethod.T ext) = 0 Then
' Create a DataTable of data to use for Registry Data.
InitializeTable ()
' Bind the DataGrid to the DataTable.
dtgRegistry.Dat aSource = dataTable
Else
If Not IsNothing(dataT able) Then
dataTable.Clear ()
End If
End If
End Sub
Private Sub btnSave_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnSave.Click
Dim objRegKey As RegistryKey
Dim sKeyValue As String
Dim sSelectedNode As String
sSelectedNode = tvRegistry.Sele ctedNode.FullPa th
sSelectedNode = Mid(sSelectedNo de, Len("HKEY_LOCAL _MACHINE\") + 1)
MessageBox.Show (sSelectedNode)
objRegKey = Registry.LocalM achine.OpenSubK ey(sSelectedNod e, True)
'read data from the data grid and write it to the registry
MessageBox.Show (dsConfiguratio n.Tables(0).Col umns.Count)
'sKeyValue = objRegKey.GetVa lue("FromName", "HP")
End Sub
End Class
"scorpion53 061" <sc************ @yahoo.com> wrote in message
news:Oc******** ******@TK2MSFTN GP10.phx.gbl...
Please post this code you are using to fill a datagrid from a datatable.
"Tejpal Garhwal" <te************ @ocs.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. .. My Datagrid is bound to Datatable which i am creating and populating the
datagrid with this datatable at the run time.
"William Ryan" <do********@com cast.nospam.net > wrote in message
news:Om******** ******@TK2MSFTN GP11.phx.gbl... Everything you can bind the grid to, a collection, datatable,
dataview, and even dataset, will have something that's enumerable and can be
counted...it depends what you are binding to.
DataTable.Rows. Count should work as Mr. B mentioned unless you are binding to something else. What is the grid bound to? If a DataView, then
Dataview.rows.c ount. If a strongly typed collection then
Collection.Item s.Count.
HTH,
Bill
"Tejpal Garhwal" <te************ @ocs.com> wrote in message
news:OY******** ******@TK2MSFTN GP10.phx.gbl...
> Thanks Bruce, but your code with return the row count of Datatable
not the > DataGrid. I need the row count for DataGrid.
>
> I know you have the answer for this too :)
>
> "Tejpal Garhwal" <te************ @ocs.com> wrote in message
> news:uL******** ******@TK2MSFTN GP09.phx.gbl...
> > I have datagrid filled with some data rows. At the run time i want
know > how
> > many total rows are there in the data grid ?
> >
> > Any idea ? Any Suggestions ?
> >
> > Thanks in advance
> >
> > Tej
> >
> >
>
>