1我正在尝试通过列表框中的多个选定项检索数据,但我只能检索一个项目。我需要帮助? [英] 1 I'm trying to retrieve data by multiple selected items in listbox but I can only retrieve one item. I need help?

查看:63
本文介绍了1我正在尝试通过列表框中的多个选定项检索数据,但我只能检索一个项目。我需要帮助?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


chart1.ChartAreas[0].AxisX.LabelStyle.Enabled = true;


SqlDataAdapter da = new SqlDataAdapter();
cmd.Parameters.AddWithValue("@Tarih1", convert);
cmd.Parameters.AddWithValue("@Tarih2", convert2);
da.SelectCommand = cmd;
chart1.Titles.Add("DC POWER" + " ( " + convert + "  -  " + convert2 + " ) ");
cmd.CommandType = CommandType.Text;


//Drawing Graph
for (int i = 0; i < listBox1.SelectedItems.Count; i++)
{

    chart1.DataSource = cmd;
    string query = "SELECT AVG(carpim ) as " + listBox1.SelectedItems[i].ToString() + " FROM (SELECT AVG(" + listBox1.SelectedItems[i].ToString() + ") AS carpim FROM se_dc_power INNER JOIN  poa ON se_dc_power.dc_pwr_date = poa.poa_date  inner join se_modules_temp on dc_pwr_date = modules_temp_date  and dc_pwr_date between @Tarih1 and @Tarih2 and TEMP_" + listBox1.SelectedItems[i].ToString() + "      is not null  and poa_south is not null and  poa_south>0 and  se_dc_power." + listBox1.SelectedItems[i].ToString() + ">0       and se_dc_power." + listBox1.SelectedItems[i].ToString() + "    is not null group by dc_pwr_date having AVG(" + listBox1.SelectedItems[i].ToString() + ")>10       and AVG(poa_south)>50)x";
    cmd.CommandText = query;
    chart1.Series.Add(listBox1.SelectedItems[i].ToString());
    chart1.Series[i].ChartType = SeriesChartType.Column;
    chart1.Series[i].LegendText = listBox1.SelectedItems[i].ToString();

    chart1.Series[i].YValueMembers = listBox1.SelectedItems[i].ToString();
    chart1.Series[i].ToolTip = listBox1.SelectedItems[i].ToString();
    chart1.Series[i].IsValueShownAsLabel = false;
    query = "";

}


推荐答案

你好metu02,

Hi metu02,

这是因为你只能在列表框中同时选择一个项目,所以名为"i"的变量是在for循环中总是为0,所以你只能一直显示
Chart1.Series [0]

That is because you can only select one item at the same time in listbox, so the variable named "i" within for-loop is always 0, so you just can only display Chart1.Series[0] all the time.

你可以参考以下代码为您的目的,我不知道你在哪里添加上面的代码,也不知道代码中的一些变量,所以我只做一个简单的演示并添加一个列表来模拟数据源,请参考如下所示:

You can refer to the following code for your purpose, I'm not sure where do you add the code above, and also do not know some variables in the code, so I just make a simple demo and add a list to simulate the data source, please refer to it as below:

        int i = 0;
        List<int> array = new List<int> { 9, 5, 2, 7, 1, 3, 2, 6 };
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {            
            i++;
            chart1.Series.Add(listBox1.SelectedItem.ToString());
            chart1.Series[i].ChartType = SeriesChartType.Column;
            chart1.Series[i].LegendText = listBox1.SelectedItem.ToString();

            //chart1.Series[i].YValueMembers = listBox1.SelectedItems[i].ToString();
            for (int j = 0; j < 7; j++)
            {
                chart1.Series[i].Points.AddXY(j + 1, array[j]);
            }

            chart1.Series[i].ToolTip = listBox1.SelectedItem.ToString();
            chart1.Series[i].IsValueShownAsLabel = false;
        }

希望这会有所帮助!

最好的问候,

Stanly


这篇关于1我正在尝试通过列表框中的多个选定项检索数据,但我只能检索一个项目。我需要帮助?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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