隐藏DataGrid中的空行

时间:2016-07-06 16:14:38

标签: vb.net wpfdatagrid

下午好。我能够将数据填充到vb.net中的DataGrid控件中。但是,当您从第一个下拉列表中选择不同的公司时,会有空行。这是因为每个选择的结果是输出数据网格中的所有报告,但只显示适合公司的报告,因此那些不合适的报告留空。但是,我坚持如何隐藏那些空行。我看过其他来源,但都没有用。如何隐藏空行?

这是我的后端:

Apply fix "Add Permission"

...和我的数据网格前端。任何帮助将不胜感激。

        Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
    DropDownList2.Items.Clear()

    'DropDownList2.Enabled = False
    'DropDownList3.Enabled = False
    'TextBox1.Enabled = False

    If DropDownList1.SelectedIndex > 0 Then
        Dim sConstr As String = ConfigurationManager.ConnectionStrings("ds17701ConnectionString").ConnectionString
        Dim Conn As New SqlConnection(sConstr)
        Dim ds As New DataSet()
        Dim dt As New DataTable
        Dim valsql As String = ""
        Dim valsql1 As String = ""
        Dim ds_Reports As New DataSet()


        Dim parentitem As DataRow
        Dim childitem As DataRow

        'populates membership status once company selected
        valsql = "SELECT [CompanyID], [CompanyName], [MemberTypeID], [MembershipStatus], [GroupID]  FROM CompanyList WHERE COMPANYID = " & DropDownList1.SelectedValue


        valsql1 = "SELECT REPORTID, REPORTNAME, REPORTCODE FROM REPORTLIST WHERE ReportVisible = 1"
        valsql1 = valsql1 & ";SELECT c.ReportID, c.COMPANYID, rl.ReportName FROM  CompanyReportListTable c, ReportList rl WHERE c.reportid = rl.ReportID and rl.ReportVisible = 1 and CompanyID = " & DropDownList1.SelectedValue



        Using Conn
            Conn.Open()
            Dim comm As New SqlCommand(valsql, Conn)
            Dim da As New SqlDataAdapter(comm) 'da serves as the new sqldataadapter for my sqlcommand
            da.Fill(ds)
            'da.Fill(dt)

            da.SelectCommand.CommandText = valsql1
            da.Fill(ds_Reports)



        End Using

        ds_Reports.Relations.Add("CompanyReport", ds_Reports.Tables(0).Columns("ReportID"), ds_Reports.Tables(1).Columns("ReportID"))



        valGrid1.DataSource = ds_Reports.Tables(0)
        valGrid1.DataBind()




        For i = 0 To ds.Tables(0).Rows.Count - 1
            If ds.Tables(0).Rows(i).Item(3).ToString = "M" Then
                DropDownList2.Items.Insert(0, "Member")
                DropDownList2.Items.Insert(1, "Non-Member")
                TextBox1.Text = "M"
            Else
                DropDownList2.Items.Insert(0, "Non-Member")
                DropDownList2.Items.Insert(1, "Member")
                TextBox1.Text = "NM"
            End If

        Next


    Else

        DropDownList2.Items.Clear()
        DropDownList3.Items.Clear()
        TextBox1.Text.ToString()
        DropDownList1.Items.Clear()
    End If
End Sub

1 个答案:

答案 0 :(得分:0)

SELECT COLUMNS FROM TABLE WHERE COLUMN IS NOT NULL