First off, I apologize since I do not have my code already done in front of me to post, but I've been doing a bit of research with no real guidance or understanding on what to do.

I've created a dgv as a seperate form from my main one, consisting of two set columns and rows created as needed. When the user clicks the 'validate' button (on the main form), several conditional statements are stepped through. If all conditional statements are met, a messagebox displays that the form was validated, but if some are not met, I would like the results (which i would have in the past put in messageboxes) to be displayed in datagridview.

I'm just having trouble with how to write these results to the dgv form. A friend suggested I also look in Linq statements. I've gone a brief tutorial regarding them, but since I'm so new, I'd prefer to stay away from them. At least for now until I can get the basics underwrap.

Dani AI

Generated

As described, the goal is to show validation results in a separate DataGridView form instead of popping MessageBoxes. This is simple without LINQ. Two practical patterns work well: 1) expose a small public method on the validation form that adds a row to the DataGridView, or 2) collect ValidationResult objects in a list (or BindingList/DataTable) and bind that list to the DataGridView once validation finishes. ’s DB-question is not needed here unless validation results must be persisted.

A quick direct-add example (keep columns created in Designer or create them at runtime):

Public Sub AddValidationResult(severity As String, msg As String, solution As String)
    If DataGridView1.Columns.Count = 0 Then
        DataGridView1.Columns.Add("Severity","Severity")
        DataGridView1.Columns.Add("Message","Message")
        DataGridView1.Columns.Add("Solution","Solution")
    End If
    DataGridView1.Rows.Add(severity, msg, solution)
End Sub

A cleaner, more maintainable approach uses a BindingList so the grid updates automatically and column ordering matches object properties:

Public Class ValidationResult
    Public Property Severity As String
    Public Property Message As String
    Public Property Solution As String
End Class

Private ReadOnly results As New System.ComponentModel.BindingList(Of ValidationResult)

Public Sub New()
    InitializeComponent()
    DataGridView1.AutoGenerateColumns = True
    DataGridView1.DataSource = results
End Sub

Public Sub AddResult(r As ValidationResult)
    results.Add(r)
End Sub

Practical notes: run validations on the UI thread or Marshal calls with Invoke when adding rows from a background thread; collect many results first (less annoying than many popups); avoid tight coupling by passing a list to the validation form (or exposing a single AddResult method). For visual clarity, set row cell styles after adding (colour warnings/errors) and ensure the form is shown once rather than recreated repeatedly.

Recommended Answers

All 2 Replies

you want to use conditions in your db quries ? please be for specific regarding your desired result.

Regards

Yes, I would like to use conditional statements. For example, if textboxA.text = "" and textboxB.text <> "" then display message in dgv. Column one displays whether it's a warning message or error message. Column 2 displays what the error/warning is and a solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.