我创建了具有 datagridview 控件的用户控件。并且 datagridview 正在从文本文件中获取数据以动态创建行和列。我将该用户控件添加到面板。dgv 的一列是可编辑的。我想要列表中的可编辑列值。我得到了除最后一行值之外的所有值。
主窗体代码
public static List<string> testValue = new List<string>();
private void SavetoolStripMenuItem1_Click(object sender, EventArgs e)
{
List<string> dummy = new List<string>();
foreach (Control p in panelUC.Controls)
{
if (p is uc_protectionTbl1)
{
dummy = ((((uc_protectionTbl1)p).obsValue));
testValue.AddRange(dummy); //here I want all values
}
if (p is uc_performResult)
{
}
}
用户控件的代码
private List<string> listObs = new List<string>();
private string obs = null;
public List<string> obsValue
{
get
{
foreach (DataGridViewRow row in dgv_uc.Rows)
{
obs = row.Cells["Observed(Sec)"].Value.ToString();
listObs.Add(obs);
}
return listObs;
}
}
In testValue list index I am getting these values
[0] = "1";
[1] = "2";
[2] = "3";
[3] = ""; //here I want "4"
And listObs list I am getting following values
[0] = "3";
[1] = ""; //here I also want "4"
My TextFile from where I designed dgv
TestType=Phase Loset Over Current Protection Test (I>)
Heading=SrNo||Injected Current||Rated
Current||Char||Pickup(xIp)||TMS||STD]||Observed(Sec)
Value=Test-1||0.4||1||NINV3.0||0.2||0.1||0.95-1.00-1.05
Value=Test-2||7.0||1||NINV3.0||1.0||0.5||1.68-1.76-1.85
TestType=Earth Lowset Over Current Protection Test (Ie>)
Heading=SrNo||Injected Current||Rated
Current||Char||Pickup(xIn)||TMS||STD||Observed(Sec)
Value=Test-3||0.2||1||NINV3.0||0.1||0.1||0.95-1.00-1.05
Value=Test-4||7.0||1||NINV3.0||1.0||0.5||1.68-1.76-1.85
当我阅读“SrNo”列而不是“Observed(Sec)”列时,我从 SrNo 列中获得了所有值。那为什么我无法阅读可编辑的“已观察(秒)”列?
我无法理解我错过了什么。请帮我解决这个问题。提前致谢!!