|
i have a datagrid with 4 columns on form 1. i also have 4 textboxes on form2. when edit button is selected i need the textboxes to be filled with the selected row. any suggestions?
|
|
|
|
|
Which form is the Edit button on?
|
|
|
|
|
the edit button is on form 2. and the textboxes are on form1.
|
|
|
|
|
The way to do what you want is by using delegates. In Form1 where the DataGrid is you add a handler that tells Form2 the address of the sub that will update the text boxes. You also have to write that sub. In Form2 you define an event that has the same signature as the subroutine you created in Form1. In the button click event you raise the event you defined passing in the text boxes to be updated. See the code below.
Public Class Form1
Inherits System.Windows.Forms.Form
Private f2 As New Form2
Private dt As New DataTable("Four Columns")
Private dr As DataRow
Private dc As DataColumn
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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 DataGrid1 As System.Windows.Forms.DataGrid
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.DataGrid1 = New System.Windows.Forms.DataGrid
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(24, 16)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(480, 176)
Me.DataGrid1.TabIndex = 0
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(544, 273)
Me.Controls.Add(Me.DataGrid1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' Add columns
dc = New DataColumn
With dc
.ColumnName = "Column 1"
.DataType = System.Type.GetType("System.String")
.ReadOnly = True
End With
dt.Columns.Add(dc)
dc = New DataColumn
With dc
.ColumnName = "Column 2"
.DataType = System.Type.GetType("System.String")
.ReadOnly = True
End With
dt.Columns.Add(dc)
dc = New DataColumn
With dc
.ColumnName = "Column 3"
.DataType = System.Type.GetType("System.String")
.ReadOnly = True
End With
dt.Columns.Add(dc)
dc = New DataColumn
With dc
.ColumnName = "Column 4"
.DataType = System.Type.GetType("System.String")
.ReadOnly = True
End With
dt.Columns.Add(dc)
' Connect Datagrid to table
DataGrid1.DataSource = dt.DefaultView
' Hard code DataRow
dr = dt.NewRow
dr(0) = "Saverio"
dr(1) = "1962"
dr(2) = "45"
dr(3) = "USC"
dt.Rows.Add(dr)
dr = dt.NewRow
dr(0) = "Jonathan"
dr(1) = "1983"
dr(2) = "22"
dr(3) = "Routers"
dt.Rows.Add(dr)
dr = dt.NewRow
dr(0) = "Jose"
dr(1) = "1947"
dr(2) = "58"
dr(3) = "US Navy"
dt.Rows.Add(dr)
f2.Show()
' Add the event handler that communicates form2
AddHandler f2.TransferData, AddressOf SendDataToForm
End Sub
' Sends the data to form2 when the button on form2 is clicked
Private Sub SendDataToForm(ByRef tb1 As TextBox, ByRef tb2 As TextBox, _
ByRef tb3 As TextBox, ByRef tb4 As TextBox)
' Set the textboxes in form2 with the currently selected row
' in the datagrid
tb1.Text = dt.Rows(DataGrid1.CurrentRowIndex).ItemArray(0).ToString()
tb2.Text = dt.Rows(DataGrid1.CurrentRowIndex).ItemArray(1).ToString()
tb3.Text = dt.Rows(DataGrid1.CurrentRowIndex).ItemArray(2).ToString()
tb4.Text = dt.Rows(DataGrid1.CurrentRowIndex).ItemArray(3).ToString()
End Sub
End Class
Public Class Form2
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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 TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.TextBox4 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(152, 32)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(152, 72)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.TabIndex = 1
Me.TextBox2.Text = ""
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(152, 112)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.TabIndex = 2
Me.TextBox3.Text = ""
'
'TextBox4
'
Me.TextBox4.Location = New System.Drawing.Point(152, 152)
Me.TextBox4.Name = "TextBox4"
Me.TextBox4.TabIndex = 3
Me.TextBox4.Text = ""
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(32, 88)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 4
Me.Button1.Text = "Button1"
'
'Form2
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox4)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Name = "Form2"
Me.Text = "Form2"
Me.ResumeLayout(False)
End Sub
#End Region
' The event that is raised when the button is clicked
Public Event TransferData(ByRef tb1 As TextBox, ByRef tb2 As TextBox, _
ByRef tb3 As TextBox, ByRef tb4 As TextBox)
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
' Semds the reference of the four textboxs to form1 and fills them
' they are sent ByRef so what form1 puts in to them will be displayed
' automatically
RaiseEvent TransferData(TextBox1, TextBox2, TextBox3, TextBox4)
End Sub
End Class
I hope that this is of some help
|
|
|
|
|
Capture the Click event and use grid property "CurrentRowIndex" to know which row was clicked then you should be able to update the textboxes using row, column index.
Example:
<br />
dim row as Integer = myGrid.CurrentRowIndex<br />
for col as Integer = 0 to 3<br />
myGrid(row,col) = textboxArray(col).Text<br />
Next<br />
|
|
|
|
|
When you click the button
set a binding Object for each Object Form ...
|
|
|
|
|
Hi,
Does anybody know how to print Pivot Tables through vb6 and using OWC ?
If a solutions exists, can someone provide me with some code.
Thanks
J.Jay
|
|
|
|
|
Hello all hope all is good and fine
i am making an application which have a main form opened at first this main form contain a menu half of thi menu is enabled and the other half is not enabled so the user will use the enabled part when he use it it will ask for a password if the user enter the password right so the not enabled half of the menu will be enabled
i wanna some ideas for how to achieve that
i have think and make that code :
Dim Str As String
Dim Str1 As String
Dim Str2 As String
Str = "Hema"
Str1 = "U Can Access As The Manager Now"
Str2 = "The Password is incorrect"
Dim F1 As Form1
F1 = New Form1()
If (TextBox1.Text.Equals(Str)) Then
MessageBox.Show(Str1)
F1.MenuItem5.Enabled = True
F1.MenuItem6.Enabled = True
F1.MenuItem7.Enabled = True
F1.MenuItem8.Enabled = True
F1.Update()
F1.Activate()
Me.Hide()
F1.ShowDialog()
Else
MessageBox.Show(Str2)
End If
that piece of code work when the user enter the password and click enter
the problem in it is it open another main form so there is two i wanna only to change the property of the menuitem on the same form which is already opened
hope anyone could help me
thanks in advance
Gego
|
|
|
|
|
It's better to have a centralized place to know whether the forms should have additional menu items enabled based on the type of user logged in; therefore, on your MainForm you can store a variable to keep track of the user type.
This way you can have several forms open and if the user activates any of them by entering the correct password then that form should tell it's parent Mainform about the new user type (admin) and Mainform can loop through each form to set the user type and each form should know what menu items to activate based on user type.
|
|
|
|
|
I have a form and it has a textBox that customers enter money values inside .
Here is the format that i need:
$$$.$$$.$$$ --> 123.456.789 $
I need 3 digits after last point.That must be 2 digits as cent(like 9.95$) but i need 3 digits.
Should someone help me about this..
I need any code that works or gives idea at least.
Thanx..
--junior coder--
|
|
|
|
|
Do you want to limit what people can type as they type, or validate after they have typed something ? A regex to validate the input would be easiest, and if it fails, put the focus back in the textbox.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I am using following code for erasing functionality of freehand drawing.
while excuting this exception comes in system.drawing.dll. Although below code will be working fine but when mouse is moving fast then generate exception.Drawing of lines have been done on paint event.
Private Sub picboard_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picboard.MouseMove
If SetEraser = True Then
If e.Button = MouseButtons.Left Then ' draw a filled circle if left mouse is down
Dim clr As Integer
Dim xmax As Integer
Dim ymax As Integer
Dim x As Integer
Dim y As Integer
'' Get the bitmap and its dimensions.
Dim bm As Bitmap = picboard.Image
xmax = bm.Width - 1
ymax = bm.Height - 1
bm.MakeTransparent()
For x = e.X To e.X + 10
For y = e.Y To e.Y + 10
' Convert this pixel.
If bm.IsAlphaPixelFormat(PixelFormat.Alpha) = True Then
With bm.GetPixel(x - 3, y - 3).Transparent
bm.SetPixel(x - 2, y - 2, color.FromKnownColor(KnownColor.Transparent))
End With
' Display the results.
picboard.Image = bm
For i As Integer = 0 To 13
path(i) = New GraphicsPath
path(i).Reset()
Next i
Next y
Next x
End If
Else
If e.Button = MouseButtons.Left Then ' draw a filled circle if left mouse is down
Try
mousePath.AddLine(e.X, e.Y, e.X, e.Y) 'Add mouse coordiantes to mousePath
Catch
MsgBox("No way, Hose!")
End Try
End If
picboard.Invalidate() 'Repaint the PictureBox using the PictureBox1 Paint event
End If
End Sub
|
|
|
|
|
Hello all,
I am searching on the net for 2 days and I am reading a lot about Hooking and Injecting your own dll's into another process, but I don't get clear what technique is usefull for me. Let me explain what I want to accomplish.
I want to monitor a 3rd party application what actions a user takes, like he opened an options window and on the close button click I want to get the values he entered. Or he opened a process that takes a while (like processing a document).
I looked into some things, but can get a clear view on this.. Can someone helps me out?
Many thanks in advance,
Derck
(P.S. I don't find many vb.net samples on hooking or subclassing 
|
|
|
|
|
|
Hi,
Thanks for your reply.. I already looked into this article, but I need a way to monitor 3rd party applications where I don't have any source from.. I am looking for a couple days now and I don't get a clear picture where to start. I know it's not simple, but I need to know what technique is useful for me..
Thanks in advance!
|
|
|
|
|
Plain and simple, you can't without in-depth knkowledge of the 3rd party app. There are two ways:
1.) Use DDE
2.) Get the Window Handle and use some API like we did in VB6 to subclass that windows' WndProc event into your own window.
I'll tell you now, since every window, including controls, have their own WndProc, you're not going to be able to write a "Global" handler for some app's events. Unless this 3rd party app is supplying an API (like Adobe or MS Word, Outlook for example), you can't do it.
|
|
|
|
|
Many thanks! I will look into the options you gave me..
What I need is
1) Detects a user close the options form (like windows messenger)
2) Capture and save the values he entered..
I am not making a global spy util (maybe it is), but I want to monitor an application like Crystal Reports what actions the user did and what data he saw... Maybe there are some other options?
Thanks!
|
|
|
|
|
Plz tell me how to bind the data grid control in VB.NET? Plz tell me the complete code of filling the entries from the database (SQL Server 2000).
Arfan Qadir
Virtual University of Pakistan
Cell # +92(333)4283103
|
|
|
|
|
Firstly you have to put a dataGrid inside your form, than paste the code below inside your Form1.vb page
here is the simple datagrid code:
-----------------------------------
Imports System.Data.SqlClient
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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 Button1 As System.Windows.Forms.Button
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents UserControl11 As maskedTextBox.MaskeliTextBox
Friend WithEvents reportDocument1 As CrystalDecisions.CrystalReports.Engine.ReportDocument
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.reportDocument1 = New CrystalDecisions.CrystalReports.Engine.ReportDocument
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(480, 48)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Sorgula"
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(24, 184)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(648, 224)
Me.DataGrid1.TabIndex = 1
'
'reportDocument1
'
Me.reportDocument1.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.DefaultPaperOrientation
Me.reportDocument1.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize
Me.reportDocument1.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Upper
Me.reportDocument1.PrintOptions.PrinterDuplex = CrystalDecisions.Shared.PrinterDuplex.Default
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(704, 430)
Me.Controls.Add(Me.DataGrid1)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As New SqlConnection("Server=.;Database=pubs;uid=sa;pwd=;")
conn.Open()
Dim comm As New SqlCommand("Select * From Employee")
Dim adp As SqlDataAdapter = New SqlDataAdapter(comm.CommandText, conn)
Dim ds As New DataSet
adp.Fill(ds)
DataGrid1.DataSource = ds
End Sub
End Class
--junior coder--
|
|
|
|
|
Hye guys
I have used MSDN help to create one remoting application and it runs fine. Now I have build my application and having some problems in it
My remote class is Project1.class1 which returns different variables like dataset,datatable etc,.... when I compile the project through Vbc.exe it gives error but it works fine with build from menu.. I have seen many examples and every one compiles through Vbc...
Why we need to compile project through vbc ??? why not build option ???
Now in hosting application. (note: My remote class is Project1.Class1)
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown
="" mode="Singleton" type="RemotableType, RemotableType" objecturi="RemotableType.rem">
<channels>
<channel ref="http" port="8989">
in this config file in wellknow tag what should I put against type and objectURi..
Your support will be highly appreciated... + if any one knows any document for client configuration with each and every aspects + about Vbc do let me know
|
|
|
|
|
Hi everybody
Does anyone know how can I design my report in landscape mode. I don't know how can I enlarge the margins of my Report.
Thanks in Advance
|
|
|
|
|
If you're using it inside the .NET IDE, [right-click --> choose designer --> Printer setup --> change to landscape].
|
|
|
|
|
hi to you all,
i need to search group of objects in an arraylist and the only reference i have is their IDs,
is there a fast way to search those objects?
iterating through the arraylist again and again would be quite slow...
thanks in advance,
cheers!
Fuel2Run
|
|
|
|
|
|
I think it's to late to use a different collection, i'll iterate.
thanks anyway!
Cheers
Fuel2Run
|
|
|
|