首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >datagridview和NumericUpDown?

datagridview和NumericUpDown?
EN

Stack Overflow用户
提问于 2011-05-27 22:37:40
回答 1查看 1.7K关注 0票数 0

我有一个NumericUpDown盒子,根据它的值,我想将字母插入到DataGridView中。下面是我的代码,但是它没有插入到我想要的列中。

代码语言:javascript
复制
if (MarkNumericUpDown.Value < 50)
{
    //dataGridView1.Rows.Add("F");
}
else if (MarkNumericUpDown.Value > 50 && MarkNumericUpDown.Value <= 64)
{
    //dataGridView1.Rows.Add("D");
}
else if (MarkNumericUpDown.Value > 64 && MarkNumericUpDown.Value <= 68)
{
    //dataGridView1.Rows.Add("D+");
}
else if (MarkNumericUpDown.Value > 68 && MarkNumericUpDown.Value <= 72)
{
    //dataGridView1.Rows.Add("C-");
}
else if (MarkNumericUpDown.Value > 72 && MarkNumericUpDown.Value <= 76)
{
    //dataGridView1.Rows.Add("C");
}
else if (MarkNumericUpDown.Value > 76 && MarkNumericUpDown.Value <= 80)
{
    //dataGridView1.Rows.Add("C+");
}
else if (MarkNumericUpDown.Value > 80 && MarkNumericUpDown.Value <= 84)
{
    //dataGridView1.Rows.Add("B-");
}
else if (MarkNumericUpDown.Value > 88 && MarkNumericUpDown.Value <= 92)
{
    //dataGridView1.Rows.Add("B");
}
else if (MarkNumericUpDown.Value > 92 && MarkNumericUpDown.Value <= 96)
{
    //dataGridView1.Rows.Add("B+");
}
else if (MarkNumericUpDown.Value > 96 && MarkNumericUpDown.Value <= 100)
{
    //dataGridView1.Rows.Add("A-");
}
EN

回答 1

Stack Overflow用户

发布于 2011-05-27 23:04:18

我怀疑您更感兴趣的是Cells值,而不是Rows值。尝试如下所示:

代码语言:javascript
复制
        if (MarkNumericUpDown.Value < 50)
        {
            int index = dataGridView1.Rows.Add();
            dataGridView1.Rows[index].Cells[1].Value = "F";
        }
        else if (MarkNumericUpDown.Value > 50 && MarkNumericUpDown.Value <= 64)
        {
            int index = dataGridView1.Rows.Add();
            dataGridView1.Rows[index].Cells[2].Value = "D";
        }

更新:从您的图片判断,您似乎只关心编辑行,而不是添加行。如果是这种情况,您需要跟踪您所关注的行和列(请将变量名更改为对您的应用程序更有意义的名称):

代码语言:javascript
复制
int indexOfRowICareAbout = 0;
int indexOfColumnIStoreLettersIn = 4; //Judging by your picture 

if (MarkNumericUpDown.Value < 50)
{
    dataGridView1.Rows[indexOfRowICareAbout].Cells[indexOfColumnIStoreLettersIn].Value = "F";
}
else if (MarkNumericUpDown.Value > 50 && MarkNumericUpDown.Value <= 64)
{
    dataGridView1.Rows[indexOfRowICareAbout].Cells[indexOfColumnIStoreLettersIn].Value = "D";
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6153780

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档