Displaying a single row

Versaiteis

Member
Joined
Mar 12, 2010
Messages
14
Programming Experience
1-3
Alright, so here's another problem I'm having

What I have is a separate form to delete a record from the database. This form will be used so the user can select the record that they wish to delete via a combo box. When the Record is selected in the combo box a data grid view control below displays the record that the user selected.

My problem is that when the user selects the record the data grid view displays the entire dataset (and therefore the entire database) rather than just the single record.

Heres the code:

VB.NET:
 Private Sub cboRecord_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboRecord.SelectedIndexChanged
        Dim dbRow As Data.DataRow
        Select Case cboType.Text
            Case "Client"
                dbRow= Main.ds.Tables("Clients").Rows(Me.cboRecord.SelectedIndex)

                Me.dgvRecord.DataSource = dbRow
            Case "Equipment"
            Case "Supply"
            Case "Garment"
        End Select
    End Sub

Of course I realize that it the above could be simplified to read me.dgvRecord.DataSource=Main.ds.Tables("Clients").Rows(Me.cboRecord.SelectedIndex) but I did that to better "see" it
 
I don't understand why you would use a DataGridView in this situation. The whole point of a grid is to show multiple records, so if you only want one record then the grid is the wrong choice.
 
I understand this, but I want to do it to create more of a uniform look to the whole application. I don't think it really matters though, I may have stumbled upon how to do it. But it requires the use of a DataTableReader, which means more internet research -_- lol
 
If you're determined to use a grid, which I still recommend against, then all you need to do is create a DataView from your DataTable, set its RowFilter to exclude all but the row you want, then bind that to your grid.
 
Well I am curios to know what you DO recommend

but the way I did it was simple enough

all I did was have a data table reader load the info from the dataset into a new data table and simply deleted the records I did not want to show and then binding the data table to the grid.

It's purely for aesthetic purposes. It has absolutely no other function other than to provide the user with a visual of what is being deleted. And I think it adds a nice little touch of style to the form.
 
Back
Top