ClearSelection在DatagridView中不起作用? [英] ClearSelection is not working in 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("Select * From SIF Where UID=" + Convert.ToInt32(Constants.NodetooltipUnit));
DataTable dtClassificationSIFIDs = new DataTable();
dtClassificationSIFIDs = dc.GetDataTable("Select SIFID from ClassificationSIF");
if (dtfillgrid.Rows.Count > 0)
{
dgrid.DataSource = dtfillgrid;
dgrid.Columns["SIFID"].Visible = false;
dgrid.Columns["UID"].Visible = false;
//dgrid.ClearSelection();
//dgrid.Rows[0].Selected = false;
if (dtClassificationSIFIDs.Rows.Count > 0)
{
for (int i = 0; i < dtClassificationSIFIDs.Rows.Count; i++)
{
for (int j = 0; j < dgrid.Rows.Count; j++)
{
if (dtClassificationSIFIDs.Rows[i]["SIFID"].ToString().Equals(dgrid.Rows[j].Cells["SIFID"].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屋!