开发者

Set column in datagrid to invisible

I was wondering how to set a column in my datagrid to be invisible. Here is some code...

        else if (combo_View.Text == "Orders")
        {

            da.SelectCommand = new OleDbCommand("SELECT * FROM TestQuery WHERE (VendorName = @VendorName OR @VendorName = '') AND (CustomerName = @CustomerName OR @CustomerName = '')  AND ((@From IS NULL AND @To IS NULL) OR orderDate BETWEEN @From AND @To) AND (ItemNum = @ItemNum OR @ItemNum = '') AND (PO = @PO OR @PO = '') ORDER BY CustomerName", cs);

            da.SelectCommand.Parameters.Add("@VendorName", OleDbType.VarChar).Value = combo_VendorView.Text.ToString();
            da.SelectCommand.Parameters.Add("@CustomerName", OleDbType.VarChar).Value = combo_CustomerView.Text.ToString();

            if (!chk_viewAllDates.Checked)
            {
                da.SelectCommand.Parameters.Add("@From", OleDbType.Date).Value = "#" + tp_viewFrom.Value.Date.ToString("M/d/yyyy") + "#";
                da.SelectCommand.Parameters.Add("@To", OleDbType.Date).Value = "#" + tp_viewTo.Value.Date.ToString("M/d/yyyy") + "#";
            }

            else
            {
                da.SelectCommand.Parameters.Add("@From", OleDbType.Date).Value = DBNull.Value;
                da.SelectCommand.Parameters.Add("@To", OleDbType.Date).Value = DBNull.Value;
            }

            da.SelectCommand.Parameters.Add("@PO", OleDbType.VarChar).Value = txt_POLookup.Text.ToString();
            da.SelectCommand.Parameters.Add("@ItemNum", OleDbType.VarChar).Value = combo_ItemNumLookup.Text.ToString();

            dsB.Clear();
            da.Fill(dsB);

            tblEditBS.DataSource = dsB.Tables[0];
            dgv_DataLookup.DataSource = tblEditB开发者_JAVA百科S;



        }

the 14th column index is the order id/primary key. I do not want to show it but I must include it in my sql in order for my edit function to work. I want something like this

dsB.Clear();
dsB.Tables[0].Columns[14].Visible = false;
da.Fill(dsB);

unfortunately, that is not a valid command. if you can see what I'm trying to do, please help me. Thanks!

p.s. - Winforms with C#.net. Visual Studio 2010 with OLEDB database type (access)


have you tried to set the Visible-Property of the datagrid? Example:

dataGridView1.Columns[14].Visible = false;


You can do this 2 ways.

In the code where you would specify your column you want invisible when you load your datagridview

dataGridView1.Columns[14].Visible = false;

Or you can do it from the properties in the datagridview if your datagridview has a Datasource assigned to it. Go to the design view of your datagriview, a select your datagridview. Open the properties for it, choose Columns.

Set column in datagrid to invisible

From the popup dialog you can show/hide any of the columns that you want.

Set column in datagrid to invisible

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜