开发者

Drop Down List in .NET Windows application

开发者 https://www.devze.com 2023-01-22 13:15 出处:网络
First of all thanks to all, now I am getting the dropdown value change on the selection of first dropdwon. PFB the source code.

First of all thanks to all, now I am getting the dropdown value change on the selection of first dropdwon. PFB the source code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TestExcel
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            cmbpackage.Items.Add("---Please Select---");
            cmbpackage.Items.Add("HR");
            cmbpackage.Items.Add("Test");
            cmbpackage.Items.Add("DEV");
        }    
        private void cmbpackage_SelectedIndexChanged(object sender, EventArgs e) 
     { 
        string selectedValue = cmbpackage.SelectedIndex.ToString();             

        if (selectedValue == "1") 
        { 
            cmbmodule.Items.Add("ModuleHR1"); 
            cmbmodule.Items.Add("ModuleHR2"); 
            cmbmodule.Items.Add("ModuleHR3"); 

        } 

        else if (selectedValue == "2") 
        { 
            cmbmodule.Items.Add("ModuleTest1"); 
            cmbmodule.Items.Add("ModuleTest2"); 
            cmbmodule.Items.Add("ModuleTest3"); 
        } 

        else 
        { 
            cmbmodule.Items.Add("ModuleDEV1"); 
            cmbmodule.Items.Add("ModuleDEV2"); 
            cmbmodule.Items.Add("ModuleDEV3"); 
        } 

    } 

} 
}

Now I want to make index 0. I mean "Please Select" will load at the time开发者_如何学Go of page load only and not by clicking on "cmbpackage" dropdown.

Also I want to change the drop dwon values of "cmbmodule" based on selections on the cmbpackage dropdown. Currently its changing but all the values are getting stored in the "cmbmodule" dropdown. I want if I select "HR" only ModuleHR1, ModuleHR2, ModuleHR3 will display and same for rest "Test" and "DEV".


Right if I will use "cmbmodule.Items.Clear()", it will clear all my records.

What I want how can if I select "HR" only ModuleHR1, ModuleHR2, ModuleHR3 will display, same way for "Test" and "DEV", but again if I select "HR" after selecting "Test" or "DEV", it has to show only ModuleHR1, ModuleHR2, ModuleHR3. How top do this ?


What you want to do is

cmbmodule.Items.Clear();

within cmbpackage_SelectedIndexChanged so that it clears all existing values and based on your logic here, you add exactly only what you need to show based on the currently selected value.

0

精彩评论

暂无评论...
验证码 换一张
取 消