none
Add Comment row to datagridview RRS feed

  • Question

  • Hi all

    I have a Datagridview bound to datatable with several columns and rows (i.e. Customers)

    I wish to develop my own grouping Datagridview taht group customers for example by City.

    I iwsh to procede step by step

    The first step is to be able to add a row to DGV that is not on the DataTable, and that should be a simple comment line ( i..e name of the city grouped).

    The first question is : How to add a new row as comment line to a datagridview . Should I use DatagridView.Prepaint ?

    Can someone give me a code example to add row with dgv prepaint ?

    Thank you for help

    Tuesday, August 28, 2018 9:29 AM

Answers

  • Hi,

    I think the workload of redraw DataGridview is really too big, download the DataGridviewGrouper source code, and then try to modify the source code to solve your problem.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Claudio111 Friday, September 7, 2018 10:38 AM
    Thursday, September 6, 2018 8:49 AM

All replies

  • Hi,

    I can't understand, what is Comment row?
    Do you want to group Datagridview?

    https://stackoverflow.com/questions/10063770/how-to-add-a-new-row-to-datagridview-programmatically

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 29, 2018 3:11 AM
  • Hi Alex

    For comment line i mean a row that has not th same columns of others.

    In any case i wish to group my Datagridview like the following image

    So, the question is : how to add a row like the ones in the image (i.e. Citta' : GENOVA ) ?

    Wednesday, August 29, 2018 6:16 AM
  • Hi,

    Is this a third-party DataGridView?

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 29, 2018 6:31 AM
  • no, it is made by a Classe passing a normal DataGridview  to it. 


    Wednesday, August 29, 2018 11:39 AM
  • Hi,

    Repainting the DataGridview control is cumbersome and time consuming, and you can use the datagridview in DevExpress.

    Let me try to repaint it.

    Please wait.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, August 30, 2018 8:17 AM
  • I do not know what DevExpress is. I'm new VB developer and I'm studing OOP starting few moths ago. (even if I'm a very old gay that used Cobol 25 years ago).

    Now , I'm trying to group a Datagridview that should give Total for every Group for numerics columns . I'm studing DatagridViewGrouper got from CodeProject. (It is very complicated and it is in C# that I 'm  slowly converting) - HARD JOB

    So if you can help me in any way i will aprreciate it very much.

    Thanks Alex


    Thursday, August 30, 2018 6:40 PM
  • Hi,

    I tried to use DataGridviewGrouper, I think it can meet your needs.

    My code, grouped by UID.

    Imports System.Data.SqlClient
    Imports DGVGROUP
    
    Public Class Form1
        Dim constr As String = "Data Source = (localdb)\MSSQLLocalDB; Integrated Security = True ;AttachDbFileName= C:\Users\alexl2\Desktop\DataBase\Alex\alex.mdf"
        Dim conn As SqlConnection
        Dim sda As SqlDataAdapter
        Dim dt As DataTable
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Using conn = New SqlConnection(constr)
                conn.Open()
                sda = New SqlDataAdapter("Select * From Student", conn)
                dt = New DataTable()
                sda.Fill(dt)
                DataGridView1.DataSource = dt
            End Using
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim grouper = New Subro.Controls.DataGridViewGrouper(DataGridView1)
            grouper.SetGroupOn("Uid")
        End Sub
    End Class
    

    https://www.codeproject.com/Tips/995958/DataGridViewGrouper

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, August 31, 2018 7:53 AM
  • Thanks Alex

    I'm Using DatagrivViewGrouper too but unfortunatly it does not compute total for numeric column in each group.

    So I have to develop my own Grouper Class.

    Friday, August 31, 2018 2:12 PM
  • Hi,

    I can't understand what you mean,total for numeric column in where each group needs to be written?

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 3, 2018 9:33 AM
  • I mean something like this :

    Wednesday, September 5, 2018 5:20 AM
  • Hi,

    I think the workload of redraw DataGridview is really too big, download the DataGridviewGrouper source code, and then try to modify the source code to solve your problem.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Claudio111 Friday, September 7, 2018 10:38 AM
    Thursday, September 6, 2018 8:49 AM
  • Hello Alex,

    I was looking at your example but i can't get it to work.

    Can i dowload this example what you made.


    Thursday, September 6, 2018 1:27 PM
  • Hi Kees

    you can find the complete code for DGV Grouper at this CodeProject Address

    https://www.codeproject.com/Tips/995958/DataGridViewGrouper

    you must signin to download it

    Friday, September 7, 2018 10:37 AM
  • Hi Alex

    this is what I am doing .....very hard to do.

    Thank you

    Claudio

    Friday, September 7, 2018 10:38 AM
  • Hello ,

    I downloaded it en works , but when i want ot use it on another project than i can't figure it out.

    Friday, September 7, 2018 11:37 AM
  • I don't know how you added DGVGrouper to your project .

    I added it file by file , first adding a new project to my solution with DGVGrouper Name

    Than I added empty classes to the new project then copying/pasting the code from original classes of DGVGrouper

    Friday, September 14, 2018 6:36 AM