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;
using Telerik.WinControls;
using Telerik.WinControls.UI;

namespace _1418434_RadListControl
{
    public partial class RadForm1 : Telerik.WinControls.UI.RadForm
    {
        DataTable table2 = new DataTable();
        public RadForm1()
        {
            InitializeComponent();
            this.radListControl1.VisualItemFormatting += RadListControl1_VisualItemFormatting;

            DataTable table1 = new DataTable();
            table1.Columns.Add("Id", typeof(int));
            table1.Columns.Add("Name", typeof(string));
            table1.Rows.Add(1, "Indocin David");
            table1.Rows.Add(2, "Enebrel Sam");
            table1.Rows.Add(3, "Hydralazine Christoff");
            table1.Rows.Add(4, "Combivent Janet");
            table1.Rows.Add(5, "Dilantin Melanie");
            table1.Rows.Add(6, "Ashley Bella");

            radListControl1.DataSource = table1;
            radListControl1.DisplayMember = "Name";
            radListControl1.ValueMember = "Id";


            
            table2.Columns.Add("Id", typeof(int));
            table2.Columns.Add("Status", typeof(string));
            table2.Rows.Add(1, "working");
            table2.Rows.Add(2, "not working");
            table2.Rows.Add(3, "working");
            table2.Rows.Add(4, "working");
            table2.Rows.Add(5, "not working");
            table2.Rows.Add(6, "not working");


        }
        Font font = new Font("Segoe UI", 9, FontStyle.Bold);
        private void RadListControl1_VisualItemFormatting(object sender, VisualItemFormattingEventArgs args)
        {
            var dataItem = args.VisualItem.Data.DataBoundItem as DataRowView;
            var row = (DataRow)dataItem.Row;
          
            var id = (int)row["Id"];
            var status = GetStatus(id);
            if (status == "working")
            {
                args.VisualItem.Font = font;
               
            }
            else
            {
                args.VisualItem.ResetValue(LightVisualElement.NumberOfColorsProperty, Telerik.WinControls.ValueResetFlags.Local);
            }
            
        }
        private string GetStatus(int Id)
        {
            var result = string.Empty;

            for (int i = 0; i < table2.Rows.Count; i++)
            {
                var row = table2.Rows[i];
                var curretnId = (int)row["id"];
                if (Id == curretnId)
                {
                    return row["Status"].ToString();
                }
            }
            return result;
        }
    }
}
