 |
BOOK: Visual Basic 2005 Programmer's Reference  | This is the forum to discuss the Wrox book Visual Basic 2005 Programmer's Reference by Rod Stephens; ISBN: 9780764571985 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Visual Basic 2005 Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 18th, 2007, 05:44 AM
|
|
Registered User
|
|
Join Date: Jun 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
VB.NET-2005 DATAGRIDVIEW
HI,
I WAN'T TO USE COMBOBOX, TEXTBOX, CHECKBOX IN DATAGRIDVIEW
CONTROLL'S WITH CONDING.
AND ALSO USE COMBOTEXT DISTINCT QUARY.
NOTE :- NOT USE BINDING PROCESS ONLY WORK WITH CODING.
|
|

March 8th, 2008, 01:51 PM
|
|
Registered User
|
|
Join Date: Jul 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi
you can follow this code
Dim dataGridView1 As DataGridView
DataGridView1 = New DataGridView()
DataGridView1.Name = "dataGridView1"
'insert code for visual appearance here
'This create the textbox and add it to the grid
Dim colTextbox As New DataGridViewTextBoxColumn()
colTextbox.DataPropertyName = "Textbox"
colTextbox.HeaderText = "Textbox"
colTextbox.Name = "Textbox"
colTextbox.ReadOnly = True
colTextbox.Visible = False
DataGridView1.Columns.Add(colTextbox)
' Column: Gender, combo box
'
' For this column, combo box contents are specified programmatically
Dim colGender As New DataGridViewComboBoxColumn()
' Size the column width so it is wide enough to display the header
colGender.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader
colGender.DataPropertyName = "Gender"
' Specifiy the list of choices in the combo box
colGender.Items.AddRange(New String() {"Male", "Female"}) 'which can also take an icollection object
' Sort the combo box contents alphabetically
colGender.Sorted = True
' Disable sorting for the column
colGender.SortMode = DataGridViewColumnSortMode.NotSortable
colGender.HeaderText = "Gender"
colGender.Name = "Gender"
colGender.ReadOnly = False
DataGridView1.Columns.Add(colGender)
' check box
'
Dim colCheckbox As New DataGridViewCheckBoxColumn()
' Size the column width so it is wide enough to display the header
colCheckbox.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader
colCheckbox.ThreeState = True
colCheckbox.TrueValue = 1
colCheckbox.FalseValue = 0
colCheckbox.IndeterminateValue = System.DBNull.Value
colCheckbox.DataPropertyName = "Checkbox"
colCheckbox.HeaderText = "Checkbox"
colCheckbox.Name = "Checkbox"
colCheckbox.ReadOnly = True
DataGridView1.Columns.Add(colCheckbox)
i hope this will help
|
|

February 21st, 2011, 10:13 AM
|
|
Registered User
|
|
Join Date: Feb 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorting
please, my the form contain a combo box and a text box
the combo box contain the name of all the column in the data grid i.e. the database field.
I wanna sort my records by E.G combo box select Age, text box you type the age of the person (30)yrs
the other combo box, you choose another field like (state), text box you type in the state name (Malaysia)and so on..
etc...because i have five(5) combo box and five(5) text box. And is not a must that i mush fill in all records in the combo box and the text box to sort...I can enter only three, two, four or the five to sort in my records and display them in the data grid...
Please this is the kind of sorting I'm trying to do for the past 2weeks now...i have tried...no way out...Hope u understand my scenario...? thanks wait for you answer...Please I need the CODE to do my work..thanks
if am to use this code where do i place it?
Please help out with mine new post..thkx
|
|

February 21st, 2011, 12:10 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
|
|
I'm not sure I understand but it sounds like you want to find records that match criteria such as Age > 30, Name < 'S', etc.
If that's what you mean, make an array of three columns. The first one contains a ComboBox listing the fields Name, Age, Country, etc. The second contains operators such as <, >, =, LIKE, etc. The third contains textboxes where the user can enter a value.
When the user fills in the fields and clicks a button or something, the program looks through the controls and builds a WHERE clause from the pieces. For example, Age > 30. Then use that WHERE clause to filter your data.
I hope that's what you need.
|
|

February 21st, 2011, 12:28 PM
|
|
Registered User
|
|
Join Date: Feb 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Please Friend...i don't know how o use array...i want to sort my records and display it to the datagrid view...i'm using Access DB. i have five combo box and a five textbox and a search button. i want to do my sorting base on what i selected from the combobox and type it on the textbox....e.g combo box contain all the field in my table.....if i choose firstname mark and type age 30 on my txtbox,...the sorting will search for all marks and the age 30 from the DB...and the second combo box i choose state, textbox type in london. also search all user living in london and so on etc. and it's not a must that i must fill in all my five fields to do my sorting i might choose 2,3,4,5,1.combo box and txtbox to do my sorting. please i need the code....please please...help me out...i have been looking for solution for the past 2months now. if you dont mind please comment the code for me...on how to use it on the combobox and txtbox including the search button.
I will be very grateful sir....thkx. i have do the rest of my coding....myself this is the only problem i'm facing.
|
|

February 22nd, 2011, 09:08 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
|
|
|
|

February 25th, 2011, 02:58 AM
|
|
Registered User
|
|
Join Date: Feb 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Please my Update code is not working...This the code i use...can anyone help me...please i don't know why it's not updating....
ERROR....show syntax error
Dim str As String = "UPDATE Mission SET Title='" & CmbTitle.Text & "',FirstName='" & TxtFirstName.Text & "',LastName='" & TxtSurname.Text & "',DOB='" & CmbDOB.Text & "',BirthMonth='" & CmbMOB.Text & "',BirthYear=" & CmbYOB.Text & ",Address='" & RTBAddress.Text & "',City='" & CmbCity.Text & "',State='" & CmbState.Text & "',Country='" & CmbCountry.Text & "',HandPhone='" & MTBHandPhone.Text & "',Telephone='" & MTBTel.Text & "',OfficeNo='" & _
MTBOfficeNo.Text & "',FaxNo='" & MTBFaxNo.Text & "',ZipCode='" & TxtZip.Text & "',Email1='" & TxtEmail1.Text & "',Email2='" & TxtEmail2.Text & "',ChurchMinistry='" & TxtChurch.Text & "',Occupation='" & TxtOccup.Text & "',Denomination='" & CmbDenomi.Text & "',MissionTrip='" & TxtMission.Text & "',DepartDate='" & CmbDD.Text & "',DepartMonth='" & CmbDM.Text & "',DepartYear='" & CmbDY.Text & "',ReturnDate='" & CmbRD.Text & "',ReturnMonth='" & CmbRM.Text & "',ReturnYear='" & CmbRY.Text & "',PassportNo='" & TxtPassport.Text & _
"',OldNewIC='" & TxtIC.Text & "',MaritalStatus='" & CmbMarital.Text & "',Gender='" & CmbGender.Text & "',Baptized='" & CmbBaptized.Text & "',SpiritBaptized='" & CmbHBaptized.Text & "',SalvationYear='" & CmbSalva.Text & "',MinistryInvolve='" & TxtMinistry.Text & "',Remark='" & RTBRemark.Text & "',Noc='" & TxtNameCont.Text & "',Relationship='" & TxtRela.Text & "',Telephone2='" & MTBTel2.Text & "',OfficeNo2='" & MTBOffice2.Text & "',HandPhoneNo'" & MTBHPNo.Text & "',Fax='" & MTBFax2.Text & "',Adress2='" & RTBAdd.Text & "'WHERE ID=" & txtID.Text & ""
Dim cmnds As New OleDbCommand(str, con)
con.Open()
cmnds.ExecuteNonQuery()
MsgBox("Records Updated Successfully")
con.Close()
Last edited by Inope; February 25th, 2011 at 03:13 AM..
|
|

February 25th, 2011, 03:02 AM
|
|
Registered User
|
|
Join Date: Feb 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Update not working
This is the second code i'm using...still not updating my records
Please help me out....ERROR...showing syntax error in Update statement
Dim sqlupdate As String
sqlupdate = "UPDATE Mission SET Title=@Title, TxtFirstName=@TxtFirstName, LastName=@LastName, " & _
"DB=@DB, MB=@MB, YOBirth=@YOBirth, Address=@Address, City=@City, State=@State, Country=@Country, HPN=@HPN, Tel=@Tel, OfficeNo=@OfficeNo," & _
"FaxNo=@FaxNo, ZipCode=@ZipCode, Email1=@Email1, Email2=@Email2, CM=@CM, Occup=@Occup, Denom=@Denom, MT=@MT, DD=@DD, DM=@DM, DepartYear=@DepartYear, RD=@RD, RM=@RM, ReturnYear=@ReturnYear, PassportNo=@PassportNo, " & _
"OldNewIC=@OldNewIC, MaritalStatus=@MaritalStatus, Gender=@Gender, HUBB=@HUBB, HSB=@HSB, YearSal=@YearSal, MI=@MI, Remark=@Remark, Noc=@Noc, Rela=@Rela, " & _
"Tele=@Tele, OfficeNo2=@OfficeNo2, HPN2=@HPN2, Fax=@Fax, Adress2=@Adress2, WHERE ID='" & txtID.Text & "'"
Dim cmd As New OleDbCommand(sqlupdate, con)
cmd.Parameters.Add(New OleDbParameter("@Title", CmbTitle.Text))
cmd.Parameters.Add(New OleDbParameter("@FirstName", TxtFirstName.Text))
cmd.Parameters.Add(New OleDbParameter("@LastName", TxtSurname.Text))
cmd.Parameters.Add(New OleDbParameter("@DB", CmbDOB.Text))
cmd.Parameters.Add(New OleDbParameter("@MB", CmbMOB.Text))
cmd.Parameters.Add(New OleDbParameter("@YOBirth", CmbYOB.Text))
cmd.Parameters.Add(New OleDbParameter("@Address", RTBAddress.Text))
cmd.Parameters.Add(New OleDbParameter("@City", CmbCity.Text))
cmd.Parameters.Add(New OleDbParameter("@State", CmbState.Text))
cmd.Parameters.Add(New OleDbParameter("@Country", CmbCountry.Text))
cmd.Parameters.Add(New OleDbParameter("@HPN", MTBHandPhone.Text))
cmd.Parameters.Add(New OleDbParameter("@Tel", MTBTel.Text))
cmd.Parameters.Add(New OleDbParameter("@OfficeNo", MTBOfficeNo.Text))
cmd.Parameters.Add(New OleDbParameter("@FaxNo", MTBFaxNo.Text))
cmd.Parameters.Add(New OleDbParameter("@ZipCode", TxtZip.Text))
cmd.Parameters.Add(New OleDbParameter("@Email1", TxtEmail1.Text))
cmd.Parameters.Add(New OleDbParameter("@Email2", TxtEmail2.Text))
cmd.Parameters.Add(New OleDbParameter("@CM", TxtChurch.Text))
cmd.Parameters.Add(New OleDbParameter("@Occup", TxtOccup.Text))
cmd.Parameters.Add(New OleDbParameter("@Denom", CmbDenomi.Text))
cmd.Parameters.Add(New OleDbParameter("@MT", TxtMission.Text))
cmd.Parameters.Add(New OleDbParameter("@DD", CmbDD.Text))
cmd.Parameters.Add(New OleDbParameter("@DM", CmbDM.Text))
cmd.Parameters.Add(New OleDbParameter("@DepartYear", CmbDY.Text))
cmd.Parameters.Add(New OleDbParameter("@RD", CmbRD.Text))
cmd.Parameters.Add(New OleDbParameter("@RM", CmbRY.Text))
cmd.Parameters.Add(New OleDbParameter("@ReturnYear", CmbRY.Text))
cmd.Parameters.Add(New OleDbParameter("@PassportNo", TxtPassport.Text))
cmd.Parameters.Add(New OleDbParameter("@OldNewIC", TxtIC.Text))
cmd.Parameters.Add(New OleDbParameter("@MaritalStatus", CmbMarital.Text))
cmd.Parameters.Add(New OleDbParameter("@Gender", CmbGender.Text))
cmd.Parameters.Add(New OleDbParameter("@HUBB", CmbHBaptized.Text))
cmd.Parameters.Add(New OleDbParameter("@HSB", CmbHBaptized.Text))
cmd.Parameters.Add(New OleDbParameter("@YearSal", CmbSalva.Text))
cmd.Parameters.Add(New OleDbParameter("@MI", TxtMinistry.Text))
cmd.Parameters.Add(New OleDbParameter("@Remark", RTBRemark.Text))
cmd.Parameters.Add(New OleDbParameter("@Noc", TxtNameCont.Text))
cmd.Parameters.Add(New OleDbParameter("@Rela", TxtRela.Text))
cmd.Parameters.Add(New OleDbParameter("@Tele", MTBTel2.Text))
cmd.Parameters.Add(New OleDbParameter("@OfficeNo2", MTBOffice2.Text))
cmd.Parameters.Add(New OleDbParameter("@HPH2", MTBHPNo.Text))
cmd.Parameters.Add(New OleDbParameter("@Fax", MTBFax2.Text))
cmd.Parameters.Add(New OleDbParameter("@Address2", RTBAdd.Text))
con.Open()
cmd.ExecuteNonQuery()
con.Close()
Last edited by Inope; February 25th, 2011 at 03:25 AM..
|
|

February 28th, 2011, 05:21 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
|
|
In the version with all of the values written into the query string, you should examine the final string and make sure it makes sense. For example, check that all of the strings are property delimited.
In the version that uses parameters, I think you need to use ? symbols as placeholders for the values. You may also want to omit the @ symbols from the names. Here's an example that may help:
Execute a parameterized query in VB .NET
|
|
 |