|
Wait. It sounds like you're putting a ComboBox control into the DataGridView yourself??
|
|
|
|
|
Yes, I want to control datagridview.as dataset with get populated from datagrid values.The combobox will get values from another database table.
|
|
|
|
|
That made no sense at all.
Normally, you would use a form, or some textbox's, ComboBox's, or other controls on a seperate area of the form to get data to use in the search for records, populating the DataGridView with the results. You wouldn't normally use a DataGridView to get the parameters of the search.
|
|
|
|
|
I need help to create a text box that accepts only numbers and full stop in VB.Net. It was easy in vb6 but in VB.Net I am really confused. Can someone help me please,
Thank you.
|
|
|
|
|
You need to handle the KeyPress Event[^] like you did with vb6. Reagrds: Didi
|
|
|
|
|
How about using NumericUpDown control?
(I guess you are allowing '.' for user to enter decimal numbers.)
जय हिंद
|
|
|
|
|
Private Sub txt1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txt1.KeyPress
Try
If Not (Char.IsNumber(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then e.Handled = True
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
My advice is free, and you may get what you paid for.
|
|
|
|
|
Thank you very much Johan, Actually i wanted the box along with dots inbetween the numbers and I added IsPunctuation to your code. Thank you once again.
Didi, I was trying to do it as in vb6 but it was driving me mad without an answer. Ofcourse I am a beginer in VB.Net and Johan's coding is very new to me.
Danish, thanks for your reply but I needed a box with numeric values and with / without decimals to be keyed in.
Thank you all.

|
|
|
|
|
If you are used to VB6, you'll find .NET a bit confusing in the beginning, because its approach is just a little different, however just like in the example code I showed you, check out all the new properties and methods. Lots of things have become much easier to do, and I am quite sure you'll come to love it in about two weeks time, and wonder how you managed to do it all with vb6.
My advice is free, and you may get what you paid for.
|
|
|
|
|
The KeyPress code that you were given will work, just remember that if a user pastes a value into the textbox, the keypress code isn't going to stop the alpha characters like usual. It will still be possible for alpha values to get into the textbox, and you may have to add code to check for it. Just thought I'd mention it, since I've encountered that issue before.
|
|
|
|
|
Iam using the following for save
-------------------------------------------------------------------------------------
Dim DAD31 As SqlDataAdapter,DS31 As New DataSet,DTB31 As New DataTable
Dim Save_4 As String = "insert into itemmst (itm_description) values (&itm_description)"
DAD31.InsertCommand = New SqlCommand(Save_4, con)
con.Open()
Dim Trans As SqlTransaction
Trans = con.BeginTransaction
DAD31.InsertCommand.Transaction = Trans
Try
DAD31.Update(DS31.Tables(0))
Trans.Commit()
Catch ex As Exception
If Not Trans Is Nothing Then
Trans.Rollback()
End If
MsgBox(ex.Message)
End Try
con.Close()
----------------------------------------------------------------
Problem is if the
itm_description=BULB .........working nice....But if the
itm_description=COUPLING 54"x64" is not insering...because of this " and '
Better ideas are always welcome.!!!
|
|
|
|
|
It's always a bad idea to create SQL commands by manually appending strings, cause you will end up with this problem. Also, you will be vulnerable to SQL injection attacks.
In order to avoid that, you should build your command using parameters.
If you need further help with that, or some example, just let me know.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Can You Post, sample codings?
THANK YOU 
|
|
|
|
|
If I undestand correctly what you are trying to do, an example could be:
Dim Save_4 As String = "insert into itemmst (itm_description) values (@itm_description)"
Dim com As SqlCommand = New SqlCommand(Save_4, con)
Dim par As SqlParameter = New SqlParameter("itm_description", SqlDbType.Text, 255, ParameterDirection.Input, False, 0, 0, "itm_description", DataRowVersion.Current, itm_description)
com.Parameters.Add(par)
con.Open()
Dim Trans As SqlTransaction
Trans = con.BeginTransaction
com.Transaction = Trans
Try
com.ExecuteNonQuery()
Trans.Commit()
Catch ex As Exception
If Not Trans Is Nothing Then
Trans.Rollback()
End If
MsgBox(ex.Message)
End Try
con.Close()
Please have a look at the documentation for the SqlParameter class, in order to apply the correct values to all parameters for your specific needs.
If you need to do something more complex, like for example reading the data into a dataset, binding it to some UI controls, modifying it and then applying the modifications to the DB, you can have a deeper look at the SqlDataAdapter class. It has methods to automatically build your select/insert/update/delete commands and managing modifications to your datasets. You can have a look at one of the many good articles about ADO.NET on the web.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
I want to emphasize the relationship of some adjacent Cell Rows in a Column, by Drawing a 2 or 3 Pixel Line around the Group of Cells.
I read that the Microsoft DataGridView Control does not support the Individual Cell Border Style in the Current Version.
Does anyone have a routine, or suggestions that will achieve this result with the MS DataGridView Control.
Thank you for your time to read this message.
Regards, Graham
|
|
|
|
|
You may need to handle the control's paint event and draw it on top of the control.
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
|
|
|
|
|
Thank you.
And do you have some suggestions of how this could be done?
I'm just looking for some guidance here.
Regards, Graham
|
|
|
|
|
Why not set the backcolour of the highlighted cells to a slightly brighter colour! That you can do un=sing the oncellpaint event.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm using the BackColour Property for a different purpose.
Regards, Graham
|
|
|
|
|
My point still stands - if you are using red in the backcolour for highlighting a row then the cells in the block you want to highlight in that row get a slightly brighter red, the green row gets a brighter green. It may be better than having to manage the complete cell redraw to get a cell border.
Also you may want to look at Infragistics tools, one of my major complaints about their tools are the number of properties you can set on them, this may be a good thing for you.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks. I'll consider your suggestion for Plan B.
For now I'll keep looking and working on Plan A. It is more appropriate in the overall design.
Regards, Graham
|
|
|
|
|
Hi
Here is the code that I'm working on.
Imports System.Threading
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
tcpSend = New TcpSender
Dim trSend As New Thread(AddressOf tcpSend.RetrieveData)
trSend.Name = "Data Receiver"
tcpSend.Command = "Send data"
tcpSend.SysName = "Cabin1"
tcpSend.Port = 100
trSend.Start()
End Sub
Imports System.net
Imports System.Net.Sockets
Imports System.IO
Public Class TcpSender
Public Event SystemReplied(ByVal data As String)
Public Command, SysName As String, Port As Int16
Public Sub RetrieveData()
Try
Dim tcpCli As New TcpClient(SysName, Port)
Dim ns As NetworkStream = tcpCli.GetStream
Dim sw As New StreamWriter(ns)
Dim sr As New StreamReader(ns)
' Send data to the client.
sw.WriteLine(Command)
sw.Flush()
' Receive and display the response.
If Command = "Send data" Then
Dim strResult As String
'read the first line
strResult = sr.ReadLine & vbCrLf
If strResult <> "" Then
'reply has come from system so get the full data
For i As Byte = 0 To 2
strResult += sr.ReadLine & vbCrLf
Next i
RaiseEvent SystemReplied(strResult)
End If
End If
sr.Close()
sw.Close()
ns.Close()
Catch ex As Exception
'MsgBox(ex.Message)
End Try
End Sub
End Class
Private Sub SystemRepliedEventHandler(ByVal data As String) Handles tcpSend.SystemReplied
'MsgBox(data)
'create the controls to display data
'this doesn't work
Dim type As New TextBox
type.Location = New Point(100, 100)
type.Size = New Size(100, 100)
type.Text = data
Controls.Add(type)
End Sub
How to use control.invoke in the event handler. Any help would be appriciated much, as straighforwardly, I'm stuck here.
Thanks
reman
|
|
|
|
|
You must use Invoke to call a routine which will then be in the UI thread.
For example:
Dim dataStorage As String
Private Sub SystemRepliedEventHandler(ByVal data As String) Handles tcpSend.SystemReplied
dataStorage = data
Invoke(New MethodInvoker(AddressOf MyAddControl))
End Sub
Private Sub MyAddControl()
Dim type As New TextBox
type.Location = New Point(100, 100)
type.Size = New Size(100, 100)
type.Text = dataStorage
Controls.Add(type)
End Sub
You can think of a more elegant way of passing over data and such, but basically this is what you need.
It may be also interesting to consider the InvokeRequired method, which will return true if you are on a different thread than the UI. It can be useful when you need to know if you need to use Invoke . In your case it's perfectly safe to always use Invoke , but you can also change your code this way:
Private Sub SystemRepliedEventHandler(ByVal data As String) Handles tcpSend.SystemReplied
dataStorage = data
If (InvokeRequired) Then
Invoke(New MethodInvoker(AddressOf MyAddControl))
Else
MyAddControl()
End If
End Sub
Hope this will be of help.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
You cannot create controls on a seperate thread. However, your thread code can Invoke a method on the UI thread that creates the controls for it.
|
|
|
|
|
Hello all
I want to loop images in my application when form loads it loads all the images and displays last image in picture box but i want to display all the images in picture box one by one i mean it starts from image 1 to image 15 and when it's image 15 it should start from image 1 again. this is what i have done
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Call LoadImages()
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
For Me.I = 0 To 15
PictureBox1.Image = (MyImage(I))
Next I
End Sub
Private Sub LoadImages()
MyImage(0) = My.Resources.G1
MyImage(1) = My.Resources.G10
MyImage(2) = My.Resources.G11
MyImage(3) = My.Resources.G12
MyImage(4) = My.Resources.G13
MyImage(5) = My.Resources.G14
MyImage(6) = My.Resources.G15
MyImage(7) = My.Resources.G16
MyImage(8) = My.Resources.G2
MyImage(9) = My.Resources.G3
MyImage(10) = My.Resources.G4
MyImage(11) = My.Resources.G5
MyImage(12) = My.Resources.G6
MyImage(13) = My.Resources.G7
MyImage(14) = My.Resources.G8
MyImage(15) = My.Resources.G9
End Sub
it should keep displaying images until user close this application but image should be in right order according to myimage array
please help 
|
|
|
|