Results 1 to 5 of 5

Thread: I want to make a empty row between the items in DataGridView

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    I want to make a empty row between the items in DataGridView

    I used this code to show the data in DataGridView and it show me as it show in the pic in Table1. I want to make the data shows each collection same items alone. Asit show in pic in Table2. with empty row between them.
    vb Code:
    1. Dim sql As String = " SELECT B,C,D,E,F,G FROM Table1 ORDER BY B   "
    2.         conn.Open()
    3.         Dim dp As New OleDbDataAdapter(sql, conn)
    4.         Dim Table1 As New DataTable
    5.         dp.Fill(Table1)
    6.         Form1.DataGridView1.DataSource = Table1
    7.         conn.Close()
    Attached Images Attached Images  

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: I want to make a empty row between the items in DataGridView

    You can hack it by looping thru the datatable and testing the value of column B for changes. If a change occurs, insert a blank row to the table. When done, bind the table to your DGV...
    However, I would just change the background color of the DGV rows instead of inserting blank rows to the datatable.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: I want to make a empty row between the items in DataGridView

    I want to make directly from DataGridView.

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: I want to make a empty row between the items in DataGridView

    Of course you can loop the datagridviewrows collection and detect for value changes in specific cells and insert a (blank) datagridviewrow to the DGV where the change occurs. However, your DGV is bound to a datatable thus whatever changes made in it will go into the datatable also, you may better just loop the datatable. Besides, by looping the datatable and inserting blank datarows to it, you can set the rows state to unchanged so when it's time to update your database, those blank rows won't get inserted into your database table.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    syria
    Posts
    854

    Re: I want to make a empty row between the items in DataGridView

    I treid this code But it show me this error:
    "Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound".
    vb Code:
    1. Dim i As Integer
    2.         For i = 0 To DataGridView1.Rows.Count - 1
    3.             If DataGridView1.Rows(i).Cells(1).Value Like _
    4.             DataGridView1.Rows(i + 1).Cells(1).Value Then
    5.  
    6.                 DataGridView1.Rows.Add()
    7.             End If
    8.  
    9.         Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width