Skip to content

help with datagrid code

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #190699
    pharaon
    Member

    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 to

    DataGridView1.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 bible

    #190708
    autopilot
    Member

    what 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?

    #190707
    pharaon
    Member

    it’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 31102

    #190706
    autopilot
    Member

    The 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 Sub
    #190705
    pharaon
    Member

    THANKS so much auto you been great help to me man really helpful
    but i dont understand why you put this in the combobox1 code

    Dim s As String = ds1.Tables.Item(0).TableName

    can you explain that code to me please
    thanks alot agin

    #190704
    autopilot
    Member

    sorry that was for my testing and learning. forgot to remove it… it is not used or needed.

    #190703
    pharaon
    Member

    ok 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 code

        Private 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 Sub

    but 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 time

    you got my idea?

    #190702
    autopilot
    Member

    i 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 Sub

    You 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 Sub
    #190701
    autopilot
    Member

    also, you will need to add some code to handle what to do when it gets to the last verse in a chapter.

    #190700
    pharaon
    Member

    ok 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. ] 
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.