Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more: , +
Hi Guy, please i need ur help. i try to mask a row of my datagridview where a column Aktiv_Personal is checked (it means that in my Database a column Personal is from the type Bit) i try but i don't find it. Please has somebody an idea??

That is what i try

C#
        private void Btn_Worker_Click(object sender, EventArgs e)
        {
connection.ConnectionString = Properties.Settings.Default.MHIntWorkflowConnectionString;
            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            da.SelectCommand = new SqlCommand("SELECT [Name],[Vorname]," +
                " [Account Nr],[Phone Nr]" +
  " ,[EMail],[Aktiv_Personal] " +
  " FROM Worker order by (Name)", connection);
            ds.Clear();
            da.Fill(ds);
            Dgrid_Worker.DataSource = ds.Tables[0];

            CurrencyManager cm = (CurrencyManager)BindingContext[Dgrid_Worker.DataSource];
            foreach (DataGridViewRow dgvr in Dgrid_Worker.Rows)
            {

                if (dgvr.Cells["Aktiv_Personal"].Value != null && dgvr.Cells["Aktiv_Personal"].Value.Equals(1))
                {
                    dgvr.Visible = false;
                }
            }

        }


please can u Help me. what i do wrong?
thx
Posted

Insted of Hiding the row you can avoid fetching this rows.... just add the where clause in your select command

..... where Aktiv_Personal!=1 .....
 
Share this answer
 
Try to filter in the query it self, for suppose the query is like this,
VB
SELECT [Name],[Vorname]," +
                " [Account Nr],[Phone Nr]" +
  " ,[EMail],[Aktiv_Personal] " +
  " FROM Worker where [Aktiv_Personal]=true order by (Name)"


or else in the code you can identify the bit datatype is boolean only.

Hope it will solve.
 
Share this answer
 
Thx Guy but,

i find now in the book (visual C# 2010) a possibility to do it without useing my query
like this.
C#
DataView dv = ds.Tables[0].DefaultView;
dv.RowFilter = "Aktiv_Personal = (0)";/*hier is important to write zero in bracket (0) because of Bit Type. But finally i think u are Right it's the same with the Query*/
Dgrid_MitarbeiterAnsicht.DataSource = dv;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900