ClearSelection在DatagridView中不起作用? [英] ClearSelection is not working in DatagridView?

查看:71
本文介绍了ClearSelection在DatagridView中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我不想在突出显示模式下显示任何行。

默认情况下它应该是高亮显示Datagridview顶行的模式。



i尝试过Datagridview1.ClearSelection();

但仍然以突出显示的模式显示第一行。



这是我的代码



< pre>< pre lang =C ++> private void FillGridView()

{

try

{

DataTable dtfillgrid = new DataTable();

dtfillgrid = dc.GetDataTable(& quot; Select * From SIF,其中UID =& quot; + Convert.ToInt32 (Constants.NodetooltipUnit));

DataTable dtClassificationSIFIDs = new DataTable();

dtClassificationSIFIDs = dc.GetDataTable(& quot;从ClassificationSIF& quot;中选择SIFID);

if(dtfillgrid.Rows.Count& gt; 0)

{

dgrid.DataSource = dtfillgrid;

dgrid.Columns [& quot; SIFID& quot;]。可见= false;

dgrid.Columns [& quot; UID& quot;]。可见= false;

//dgrid.ClearSelection();

//dgrid.Rows [0] .Selected = false;

if(dtClassificationSIFIDs .Rows.Count& gt; 0)

{

for(int i = 0; i& lt; dtClassificationSIFIDs.Rows.Count; i ++)

{

for(int j = 0; j& lt; dgrid.Rows.Count; j ++)

{

if(dtClassificationSIFIDs.Rows [i ] [& quot; SIFID& quot;]。ToString()。Equals(dgrid.Rows [j] .Cells [& quot; SIFID& quot;]。Value.ToString()))

{

dgrid.Rows [j] .DefaultCellStyle.BackColor = Color.Green;

}

}

}

}

}

}

catch(例外情况)

{

DataClass.LogError(ex);

}

}&l t; / pre>< / pre>



让我知道你是否有任何想法。



问候,

Pawan。

解决方案

Datagridview1.SelectedIndex = -1;

试试吧

这行代码解决了你的问题


dataGridView1.Rows [0] .Selected = false;

Hi All,

I don't want to show any row in highlighted mode.
by default it should be in highlight mode for the top row of Datagridview.

i tried Datagridview1.ClearSelection();
but still the top row is displayed in highlighted mode.

here is my code

<pre><pre lang="C++">private void FillGridView()
{
try
{
DataTable dtfillgrid = new DataTable();
dtfillgrid = dc.GetDataTable(&quot;Select * From SIF Where UID=&quot; + Convert.ToInt32(Constants.NodetooltipUnit));
DataTable dtClassificationSIFIDs = new DataTable();
dtClassificationSIFIDs = dc.GetDataTable(&quot;Select SIFID from ClassificationSIF&quot;);
if (dtfillgrid.Rows.Count &gt; 0)
{
dgrid.DataSource = dtfillgrid;
dgrid.Columns[&quot;SIFID&quot;].Visible = false;
dgrid.Columns[&quot;UID&quot;].Visible = false;
//dgrid.ClearSelection();
//dgrid.Rows[0].Selected = false;
if (dtClassificationSIFIDs.Rows.Count &gt; 0)
{
for (int i = 0; i &lt; dtClassificationSIFIDs.Rows.Count; i++)
{
for (int j = 0; j &lt; dgrid.Rows.Count; j++)
{
if (dtClassificationSIFIDs.Rows[i][&quot;SIFID&quot;].ToString().Equals(dgrid.Rows[j].Cells[&quot;SIFID&quot;].Value.ToString()))
{
dgrid.Rows[j].DefaultCellStyle.BackColor = Color.Green;
}
}
}
}
}
}
catch (Exception ex)
{
DataClass.LogError(ex);
}
}</pre></pre>

let me know if u have any idea.

Regards,
Pawan.

解决方案

Datagridview1.SelectedIndex=-1;
try it
this line of code solve your problem


dataGridView1.Rows[0].Selected = false;


这篇关于ClearSelection在DatagridView中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆