Skip to content

How to Compare the ComboBox Items with UIElement Names !!!! Please Help

Guest User

Asked Sep 23, 2010, 10:53 PM EDTSolved
Share
LinkedInX

Hi All.

I just started to study on C# and I have an Application on WPF which reads datas in my XML. I read the datas with Dataset and I put them in to a ComboBox. But i have some shapes (Elipse) and I want to fill that shapes different colors if there the data which i want in ComboBox.

--<Codes>--
DataSet ds = new DataSet();
ds.ReadXml("D:\\data.xml");
foreach (DataTable tbl in ds.Tables)
{
foreach (DataRow dr in tbl.Rows)
{
cmb1.Items.Add(dr[0].ToString());
}
}
After adding items to ComboBox. For Example I want to fill Elipse1 with Red Color If There is Elipse1 item in ComboBox which comes from XML.
Is there anyone to help me :( ??
Thanks.
 

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • ✓ Accepted answer0
    Hai..

    I have doubt...wat data will in the combo box...either colours or shapes.????????.

    Some suggestions ---In the form load event fill the combo-box from xml and in the combo box selected index change event fill the shapes with the colors u want...



    With Regards
    P.Krishna Prasad
    0
  • 0
    Datas contains only Names no colors no shapes.. I want sth like : If Elipse1 selected from ComboBox the Elips1 on my design will be filled by a color..

    i cant compare it.

    if(ComboBox.SelectedItem.ToString()== !! What !!)
    {
       Elipse1.Fill = new SolidColorBrush(Colors.Blue);
    }
     
    I want sth like that ...

    Events are OK, Taking the datas with DataSet is OK. But I cant Compare ..

    Thanks.
    0
  • 0
    Hai...

    Two ways to do it...

    First way is
    if(ComboBox.SelectedItem.ToString()== "Elipse1")
    {
       Elipse1.Fill = new SolidColorBrush(Colors.Blue);
    }
     

    if(ComboBox.SelectedItem.ToString()== "Rectangle")
    {
      
    Rectangle.Fill = new SolidColorBrush(Colors.Blue);
    }
     

    Secondway is
    if(ComboBox.SelectedIndex==0)
    {
       Elipse1.Fill = new SolidColorBrush(Colors.Blue);
    }

    if(ComboBox.SelectedIndex==1)
    {
       Rectangle.Fill = new SolidColorBrush(Colors.Blue);
    }
      
    Hope i made myself clear...
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    If someway my answer helped u....don't forget to mark it as correct answer....
     
    0