本文介绍了如何从checkedlistbox中获取所选列,并在datagridview中仅显示所选列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从checkedlistbox中获取所选列并在datagridview中仅显示所选列



从下面的评论中复制的其他信息

先生我做了类似的事情,但这不是最好的方式而且代码太大

how to get selected columns from checkedlistbox and show in datagridview only selected columns

additional information copied from comment below
sir i do something like this but this is not best way and code is so large

if (dataGridView1.Rows.Count == 0)
{
   MessageBox.Show("Please first a search a record");
   return;
}

if (ch_cast.Checked == true)
{
   dataGridView1.Columns[10].Visible = true;
}
else
{
   dataGridView1.Columns[10].Visible = false;
}

if (ch_doa.Checked== true)
{
   dataGridView1.Columns[8].Visible = true;
}
else
{
   dataGridView1.Columns[8].Visible = false;
}

if (ch_dob.Checked == true)
{
   dataGridView1.Columns[3].Visible = true;
}
else
{
   dataGridView1.Columns[3].Visible = false;
}

if (ch_fn.Checked == true)
{
   dataGridView1.Columns[6].Visible = true;
}
else
{
   dataGridView1.Columns[6].Visible = false;
}

if (ch_mn.Checked == true)
{
   dataGridView1.Columns[7].Visible = true;
}
else
{
   dataGridView1.Columns[7].Visible = false;
}

if (ch_regno.Checked == true)
{
   dataGridView1.Columns[9].Visible = true;
}
else
{
   dataGridView1.Columns[9].Visible = false;
}

if (ch_smn.Checked == true)
{
   dataGridView1.Columns[5].Visible = true;
}
else
{
   dataGridView1.Columns[5].Visible = false;
}

if (checkBox1.Checked == true)
{
   dataGridView1.Columns[11].Visible = true;
}
else
{
   dataGridView1.Columns[11].Visible = false;
}

推荐答案


这篇关于如何从checkedlistbox中获取所选列,并在datagridview中仅显示所选列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 03:48