如何在我的dataGridView中隐藏一行 [英] How to hide a row in my dataGridView
本文介绍了如何在我的dataGridView中隐藏一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
盖伊,我需要您的帮助.我尝试掩盖我的datagridview的一行,其中选中了Aktiv_Personal列(这意味着在我的数据库中,Person列来自Bit类型),但是我没有找到它.请有个好主意吗?
那就是我尝试的
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
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;
}
}
}
请你能帮助我.我做错了什么?
thx
please can u Help me. what i do wrong?
thx
推荐答案
由于隐藏了行,因此可以避免获取该行....只需在select命令中添加where子句
.....where Aktiv_Personal!=1
.....
Insted of Hiding the row you can avoid fetching this rows.... just add the where clause in your select command
.....where Aktiv_Personal!=1
.....
尝试自行在查询中进行过滤,因为假设查询是这样的,
Try to filter in the query it self, for suppose the query is like this,
SELECT [Name],[Vorname]," +
" [Account Nr],[Phone Nr]" +
" ,[EMail],[Aktiv_Personal] " +
" FROM Worker where [Aktiv_Personal]=true order by (Name)"
否则在代码中您可以确定bit数据类型仅是布尔值.
希望它能解决.
or else in the code you can identify the bit datatype is boolean only.
Hope it will solve.
Thx Guy但是,
我现在在书中(Visual C#2010)发现不用我的查询就可以做到这一点
这样.
Thx Guy but,
i find now in the book (visual C# 2010) a possibility to do it without useing my query
like this.
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;
这篇关于如何在我的dataGridView中隐藏一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文