- This topic has 9 replies, 2 voices, and was last updated 14 years ago by autopilot.
-
AuthorPosts
-
January 23, 2010 at 8:39 am #190699pharaonMember
this is the code and it work fine
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
Dim sql1 As String = "select Verse1 from Bible where ChapterNum =" & Val(ComboBox2.Text)
Dim data2 As New OleDbDataAdapter(sql1, CON)
Dim ds1 As New DataSet
ds1.Clear()
data2.Fill(ds1, "Bible")
CON.Close()
DataGridView1.DataSource = ds1
DataGridView1.DataMember = "Bible"but the problem is that the datagrid display the whole verses column for the whole bible
and when i change the code toDataGridView1.DataMember = ("Bible,ChapterNum")
the datagrid display nothing
how to fix this and make the datagrid display the verses for chapter i only choose in combobox2 not the verses for the whole bibleJanuary 23, 2010 at 5:21 pm #190708autopilotMemberwhat is the DB you are connecting to? if you only want a single verse, wouldn’t it be better to query the DB for just the verse and not the whole chapter?
January 23, 2010 at 7:54 pm #190707pharaonMemberit’s access 2003 database
i dont want to display only 1 verse
i want to display the verses of the chapter i choose in the combobox2 which could be 30 to 50 verse for each chapter
but the data grid display the whole bible verses which is 31102January 25, 2010 at 12:05 am #190706autopilotMemberThe problem was in your SQL Querys. I changed several things. First, rather then using booknum, I set it up to use EnglishName to fill ComboBox1. Then I changed it to display verses based on selected EnglishName and ChapterNum. Here is the changed code with comments on my changes:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' This is not needed
'CON.Open()
' Added EnglishName to the Query
Dim sql As String = "SELECT ArabicName,EnglishName FROM BibleBookNames"
Dim Data1 As New OleDbDataAdapter(sql, CON)
Dim DS As New DataSet
DS.Clear()
Data1.Fill(DS, "BibleBookNames")
ComboBox1.DataSource = DS
' Changed the ValueMember to display EnglishName instead of BookNum
ComboBox1.ValueMember = ("BibleBookNames.EnglishName")
' This is not needed
'CON.Close()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
' Use Try-Catch to avoid problems with null returns
Try
' Redefined the SQL Query to pull chapers per book name
Dim sql1 As String = "SELECT DISTINCT Bible.ChapterNum " & _
"FROM Bible INNER JOIN BibleBookNames ON Bible.BookNum = BibleBookNames.BookNum " & _
"WHERE (((BibleBookNames.EnglishName)=""" & ComboBox1.Text & """));"
Dim data2 As New OleDbDataAdapter(sql1, CON)
Dim ds1 As New DataSet
ds1.Clear()
data2.Fill(ds1, "Bible")
Dim s As String = ds1.Tables.Item(0).TableName
ComboBox2.DataSource = ds1
ComboBox2.ValueMember = "Bible.ChapterNum"
Catch
End Try
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
' Use Try-Catch to avoid problems with null returns
Try
' Redefined Query to pull Verses based on book name & chapter selected
Dim sql1 As String = "SELECT Bible.Verse2 " & _
"FROM Bible INNER JOIN BibleBookNames ON Bible.BookNum = BibleBookNames.BookNum " & _
"WHERE (((BibleBookNames.EnglishName)=""" & ComboBox1.Text & """) AND ((Bible.ChapterNum)=" & ComboBox2.Text & "));"
Dim data2 As New OleDbDataAdapter(sql1, CON)
Dim ds1 As New DataSet
ds1.Clear()
data2.Fill(ds1, "Bible")
CON.Close()
DataGridView1.DataSource = ds1
DataGridView1.DataMember = "Bible"
Catch
End Try
End SubJanuary 25, 2010 at 2:36 am #190705pharaonMemberTHANKS so much auto you been great help to me man really helpful
but i dont understand why you put this in the combobox1 codeDim s As String = ds1.Tables.Item(0).TableName
can you explain that code to me please
thanks alot aginJanuary 25, 2010 at 3:37 am #190704autopilotMembersorry that was for my testing and learning. forgot to remove it… it is not used or needed.
January 25, 2010 at 8:31 pm #190703pharaonMemberok man
any way what i want to do with this program is to send bible verses to paltalk room
your tutorial about sending text to room is good it’s what i’ll use but what standing in front of my now is
i want to get the value of the datagridview cell into textbox or richtextbox so i can send it to the paltalkroom
i used this codePrivate Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
TextBox1.Text = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value
End Subbut the problem is i have to click each cell with the mouse so it’s text appear in the textbox which is really annoying
i want to make button in the program when i click on it
it send the current textbox text to the paltalk room and also move the selection to the next datagridview cell and make the textbox read the value without click on the cell each timeyou got my idea?
January 29, 2010 at 3:46 am #190702autopilotMemberi think this is what you want to do:
add button1 to the form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DataGridView1.CurrentCell = DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex + 1).Cells(DataGridView1.CurrentCell.ColumnIndex)
TextBox1.Text = DataGridView1.CurrentCell.Value
End SubYou will still have to code how to send it to the room.
Also note change in this event (last line before catch):
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
' Use Try-Catch to avoid problems with null returns
Try
' Redefined Query to pull Verses based on book name & chapter selected
Dim sql1 As String = "SELECT Bible.Verse2 " & _
"FROM Bible INNER JOIN BibleBookNames ON Bible.BookNum = BibleBookNames.BookNum " & _
"WHERE (((BibleBookNames.EnglishName)=""" & ComboBox1.Text & """) AND ((Bible.ChapterNum)=" & ComboBox2.Text & "));"
Dim data2 As New OleDbDataAdapter(sql1, CON)
Dim ds1 As New DataSet
ds1.Clear()
data2.Fill(ds1, "Bible")
CON.Close()
DataGridView1.DataSource = ds1
DataGridView1.DataMember = "Bible"
'Add this to update the textbox content when the datagrid is updated
TextBox1.Text = DataGridView1.CurrentCell.Value
Catch
End Try
End SubJanuary 30, 2010 at 4:55 am #190701autopilotMemberalso, you will need to add some code to handle what to do when it gets to the last verse in a chapter.
February 1, 2010 at 3:13 am #190700pharaonMemberok i did that thanks
can you tell me how to make the verse number and the verse both of them display in the textbox..so when i send to the room i want to send the verse number and the verse and if it possible to send also the book name and the chapter number for example[ Gn:1:1 ]-[ In the beginning God created the heaven and the earth. ]
-
AuthorPosts
Related
- You must be logged in to reply to this topic.