By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,131 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

limit number of rows in vb.net datagrid

P: n/a
Hi

I've a problem. Can anyone help. I would like to use datagrid for data
entry. How can I set the number of rows in the datagrid. And use the
datagrid to update the ms sql table.

regards
melson
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Melson" <we****@hotmail.com> wrote in message
news:OX**************@TK2MSFTNGP09.phx.gbl...
Hi

I've a problem. Can anyone help. I would like to use datagrid for data
entry. How can I set the number of rows in the datagrid. And use the
datagrid to update the ms sql table.

regards
melson


You could use the usual dataadaptor and dataset route.
Make your select sql choose no data.
Loop appending blank records to the dataset.
If you use stored procedures to update then you can probably do something in
there avoids actually inserting blank records to your table.
--
Regards,
Andy O'Neill
Nov 21 '05 #2

P: n/a
Hi Andy

Thanks for your help. I've done what you told me and it works. However, i'm
still frustrated because i'm still stuck with this project. Pls help. Is
there any example. I really appreciate if anyone can help me. I've tried to
solve this for weeks but still fail.
Description
I would like to create a data entry form using vb.net. It is a master-detail
windows form which the upper section is the product code(master) and the
lower section is the part information (detail). The lower section is make up
of a datagrid. First column is the part code and second column is part
description. When user pressed the Enter key in the part code column, it
opens the Part code form for the user to choose the part code. User can add
as many part code as possible with the same product code.

User is able to perform Add, Edit and Delete function on data entry form. It
is connected to ms sql database.
What I've tried

I've tried to create a windows control library with the following code
below. Then add the dll into the Toolbox. It is able to capture the Enter
key. However, there are problems which I faced.

a.. It captures Enter key in every column. e.g Part code column, Part
description column

b.. How can I open Part code form so that user can choose part code into
the datagrid

a.. How can I perform Add, Edit and Delete record which connect to ms sql.

code

Protected Overrides Function ProcessCmdKey(ByRef msg As
System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As
Boolean

If msg.WParam.ToInt32() = CInt(Keys.Enter) Then

MsgBox("entered")

SendKeys.Send("{Tab}")

Return True

End If


Return MyBase.ProcessCmdKey(msg, keyData)

End Function 'ProcessCmdKey


"Andy O'Neill" <ao***************@lycos.co.uk> wrote in message
news:iX******************@fe2.news.blueyonder.co.u k...
"Melson" <we****@hotmail.com> wrote in message
news:OX**************@TK2MSFTNGP09.phx.gbl...
Hi

I've a problem. Can anyone help. I would like to use datagrid for data
entry. How can I set the number of rows in the datagrid. And use the
datagrid to update the ms sql table.

regards
melson


You could use the usual dataadaptor and dataset route.
Make your select sql choose no data.
Loop appending blank records to the dataset.
If you use stored procedures to update then you can probably do something
in there avoids actually inserting blank records to your table.
--
Regards,
Andy O'Neill

Nov 21 '05 #3

P: n/a

"Melson" <we****@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP12.phx.gbl...
Hi Andy

Thanks for your help. I've done what you told me and it works. However,
i'm still frustrated because i'm still stuck with this project. Pls help.
Is there any example. I really appreciate if anyone can help me. I've
tried to solve this for weeks but still fail.
Description
I would like to create a data entry form using vb.net. It is a
master-detail windows form which the upper section is the product
code(master) and the lower section is the part information (detail). The
lower section is make up of a datagrid. First column is the part code and
second column is part description. When user pressed the Enter key in the
part code column, it opens the Part code form for the user to choose the
part code. User can add as many part code as possible with the same
product code.

User is able to perform Add, Edit and Delete function on data entry form.
It is connected to ms sql database.
What I've tried

I've tried to create a windows control library with the following code
below. Then add the dll into the Toolbox. It is able to capture the Enter
key. However, there are problems which I faced.

a.. It captures Enter key in every column. e.g Part code column, Part
description column
You can add handlers for all sorts.
I would think you could maybe inherit your own control from the textbox
goes in a grid and handle the return key in it.
But.
I would also suggest that this is maybe rather doing things the hard way.
Adding a column with just a button in it is maybe easier.
I think there's an example on george shepherd's faq site about adding a
button.

b.. How can I open Part code form so that user can choose part code into
the datagrid
A drop down combo is no good to you?
Lot of parts perhaps.

Hand over the calling form as an object.
Add a public procedure (method) allows the called form to set the part code.

a.. How can I perform Add, Edit and Delete record which connect to ms
sql.


Read up about dataadaptors and datasets.

Nov 21 '05 #4

P: n/a
Hi Andy

Thanks very much for your help. I've tried to add 2 component class to my
project, DataGridComboColumn.vb and NoKeyUpCombo.vb. Below are the following
code. Actually I try to amend a sample code which has combobox in datagrid
to textbox in datagrid. But having problem at AddHandler
ColumnTextBox.KeyPress, New EventHandler(AddressOf CheckEnterKey) in green
color.

Can you guide me how to solve this problem so that when Enter key is pressed
in the textbox, it will display form3. Another request is how to pass
parameter between the forms. e.g user choose part code from form3 and
display in the main form datagrid.

Thanks.

DataGridComboBoxColumn.vb code
Namespace DataGridTextBoxCombo
Public Class DataGridComboBoxColumn
Inherits DataGridTextBoxColumn

' use the derived nokeyup combo to avoid tabbing problem
Public WithEvents ColumnTextBox As NoKeyUpCombo
Private WithEvents _source As CurrencyManager
Private _rowNum As Integer
Private _isEditing As Boolean
Public Sub New()
MyBase.New()
_source = Nothing
_isEditing = False
ColumnTextBox = New NoKeyUpCombo

AddHandler ColumnTextBox.Leave, New EventHandler(AddressOf
LeaveComboBox)
AddHandler ColumnTextBox.KeyPress, New EventHandler(AddressOf
CheckEnterKey)

End Sub

Private Sub LeaveComboBox(ByVal sender As Object, ByVal e As EventArgs)
If _isEditing Then
SetColumnValueAtRow(_source, _rowNum, TextBox.Text)
_isEditing = False
Invalidate()
End If
ColumnTextBox.Hide()
End Sub

Private Sub checkkey(ByVal sender As Object, ByVal e As EventArgs)
Dim frmt As New Form3
If e.KeyChar = Chr(13) Then
frmt.Show()
End If
End Sub
NoKeyUpCombo.vb code
Namespace DataGridTextBoxCombo
Public Class NoKeyUpCombo
Inherits TextBox
Private WM_KEYUP As Integer = &H101
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_KEYUP Then
'ignore keyup to avoid problem with tabbing & dropdownlist;
Return
End If
MyBase.WndProc(m)
End Sub 'WndProc
End Class 'NoKeyUpCombo
End Namespace



"Andy O'Neill" <ao***************@lycos.co.uk> wrote in message
news:5u******************@fe3.news.blueyonder.co.u k...

"Melson" <we****@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP12.phx.gbl...
Hi Andy

Thanks for your help. I've done what you told me and it works. However,
i'm still frustrated because i'm still stuck with this project. Pls help.
Is there any example. I really appreciate if anyone can help me. I've
tried to solve this for weeks but still fail.
Description
I would like to create a data entry form using vb.net. It is a
master-detail windows form which the upper section is the product
code(master) and the lower section is the part information (detail). The
lower section is make up of a datagrid. First column is the part code and
second column is part description. When user pressed the Enter key in the
part code column, it opens the Part code form for the user to choose the
part code. User can add as many part code as possible with the same
product code.

User is able to perform Add, Edit and Delete function on data entry form.
It is connected to ms sql database.
What I've tried

I've tried to create a windows control library with the following code
below. Then add the dll into the Toolbox. It is able to capture the Enter
key. However, there are problems which I faced.

a.. It captures Enter key in every column. e.g Part code column, Part
description column


You can add handlers for all sorts.
I would think you could maybe inherit your own control from the textbox
goes in a grid and handle the return key in it.
But.
I would also suggest that this is maybe rather doing things the hard way.
Adding a column with just a button in it is maybe easier.
I think there's an example on george shepherd's faq site about adding a
button.

b.. How can I open Part code form so that user can choose part code into
the datagrid


A drop down combo is no good to you?
Lot of parts perhaps.

Hand over the calling form as an object.
Add a public procedure (method) allows the called form to set the part
code.

a.. How can I perform Add, Edit and Delete record which connect to ms
sql.


Read up about dataadaptors and datasets.

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.