MYSTERY ZILLION တွင် English သို့မဟုတ် Unicode ဖြင့်သာ အသုံးပြုခွင့်ရှိသည်။ ဇော်ဂျီ ၊ ဧရာ စသည်တို့ကို အသုံးပြုခွင့် မရှိ။ Unicode fonts များမှာ Mon3,Yunghkio, Myanamr3 စသည်များ အသုံးပြုနိုင်သည်။ Unicode Guide ကို ဒီမှာ Download ချပါ။ Zawgyi to Unicode Converter
Don't share ebook or software if nobody request. You can find free book websites on here. We are welcome for discussion or asking question instead.

DisplayMember And ValueMember Combobox

edited November 2014 in C#
namespace LibrarySystem
{
class MyGlobalVariable
{
    public static List<Tuple<int,string>> GetBookType()
    {
            List<Tuple<int, string>> myList = new List<Tuple<int, string>>();
            SqlDataReader reader = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteReader(con_string, CommandType.Text, "SELECT booktypeid,booktype FROM booktypes");
            while (reader.Read())
            {
                myList.Add(new Tuple<int, string>((Convert.ToInt32(reader["booktypeid"])), reader["booktype"].ToString()));
            }
            return myList;
        }
----OR------
   public static List<string>GetBookType()      
  {
            List<string> my_List = new List<string>();
            SqlDataReader reader = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteReader(con_string, CommandType.Text, "SELECT booktypeid,booktype FROM booktypes");
             while (reader.Read())
             {
                 my_List.Add(Convert.ToInt32(reader["booktypeid"]).ToString());
                 my_List.Add(reader["booktype"].ToString());
             }
             return my_List;
        }
}
}

public partial class FrmBooks : Form
{
    private void FrmBooks_Load(object sender, EventArgs e)
    {
            List<Tuple<int, string>> myList = MyGlobalVariable.GetBookType();
            for (int i = 0; i < myList.Count; i++)
            {
                cboBooktypeid.Items.Add(myList[i]);
            }
    }
}

Displaymember နဲ့ Value member မှာBind ချင်တာပါ။ဘယ်လိုလုပ်ရမလဲမသိတော့လို့ကူညီပေးပါ။booktypeid က Databaseမှာ intပါ။ booktypeက nvarchar(50)ပါ။

စာကြောင်းတွေပျက်သလိုဖြစ်နေလို့။public static List<Tuple<int, string>> GetBookType()လို့ရေးထားတာပါ public static ListGetBookType()လို့ရေးထားတာပါ

မှတ်ချက်များ

  • edited November 2014 Registered Users

    Use "Item1", "Item2"

    List<Tuple<int, string>> l_infoList = new List<Tuple<int, string>>();
    l_infoList.Add(new Tuple<int, string>(1, "C#"));
    l_infoList.Add(new Tuple<int, string>(2, "ASP.Net"));
    l_infoList.Add(new Tuple<int, string>(3, "PHP"));
    
    cboLanguage.DataSource = l_infoList;
    cboLanguage.ValueMember = "Item1";
    cboLanguage.DisplayMember = "Item2";
    
  • Registered Users

    ရသွားပါပြီအစ်ကို ကျေးဇူးတင်ပါတယ် ဟီးဟီး

  • edited November 2014 Registered Users

    အစ်ကို DatagridView ထဲကိုရော်ဘယ်လိုထည့်ရမလဲအစ်ကို ကျွန်တော်ထည့်တာ Column တွေပိုလာလို့။ ပြီးရင်လေအစ်ကို
    Tuple<> ကိုဘယ်ချိန်တွေမှာသုံးသင့်လဲအစ်ကို ဒီဟာက အွန်လိုင်းက ကြည့်ပီးပြန်ရေးထားတာမို့သိပ်နားမလည်လို့ပါအစ်ကို

     List<Tuple<int, string>> a_listInfo = MyGlobalVariable.GetAuthor();
    int row = dgvAuthor.Rows.Add();
    dgvAuthor.DataSource = a_listInfo;
    dgvAuthor.Rows[row].Tag = "Item1";
    dgvAuthor.Rows[row].Cells[colAuthorName.Index].Value = "Item2";
    
  • edited November 2014 Registered Users

    Tuple is a new data type introduced in .Net Framework 4.0.
    Tuple is similar to array but able to guarantee to hold multiple strong type elements and it is usefule in this case.
    You will have more understanding with code samples.
    Let's say you want to store string and int as a collection, you can use normal array like below.

    object[] l_arr = new object[2];
    l_arr[0] = 1;
    l_arr[1] = "C#";
    int l_converted = Convert.ToInt32(l_arr[0]);
    

    With above code, problem is you can not make sure 1st part is int and 2nd part is string.
    Developers can also write like below without having a problem at compile time.
    But on the 4th line, you will have a type cast exception for converting string to int.

    l_arr = new object[2];
    l_arr[0] = "C#";
    l_arr[1] = "C#";
    l_converted = Convert.ToInt32(l_arr[0]);
    

    By using tuple, you can overcome this problem by coding like below and you can also avoid type conversion.

    Tuple<int, string> l_tuple = new Tuple<int, string>(1,"C#");
    l_converted = l_tuple.Item1;
    

    Prior to 4.0, MS .Net have a datatype something like this called "KeyValuePair<TKey, TValue>".
    It can also used to hold strong type elements but it is only valid for 2 elements.
    With tuple you can create 1 to many elements with strong data types.

    Tuple<int, string, int, string> l_tuple2 = new Tuple<int, string, int, string>(1, "C#", 10, "C#2");
    

    Alternatively you could create and use custom classes to hold required elements with strong types.
    Tuple can be used to avoid creation of many classes.

    public class Sample
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }
    //------------------------------------------------
    Sample l_class = new Sample();
    l_class.ID = 1;
    l_class.Name = "C#";
    l_converted = l_class.ID;
    

    Binding tuple list to DataGridView is the same as binding to Combobox. Use Item1, Item2 as DataPropertyName.

  • Registered Users

    ဟုတ်ကဲ့ပါအစ်ကို နားလည်သွားပါပြီ ကျေးဇူးတင်ပါတယ် အစ်ကို :-D

  • edited November 2014 Registered Users

    အဲလိုထည့်လိုက်တော့ Delete၊ Cell End Edit၊ Begin Edit တစ်ခုမ လုပ်မရတော့လို့ အစ်ကိုဟီးဟီး ခဏခဏမေးရတာအားနာလာပီ

    List<Tuple<int, string>> myList = MyGlobalVariable.GetAuthor();
    dgvAuthor.DataSource = myList;
    dgvAuthor.Columns[colAuthorName.Index].DataPropertyName = "Item2";
    dgvAuthor.CurrentRow.Tag = "Item1";
    
  • Registered Users

    What happened to those events?



    If you are not forced to use Tuple List (by coding standard or anything else) and you are trying to interact with GridView, you could use normal DataTable. As you are using Microsoft Application Block, you just need to call "ExecuteDataTable" method to return DataTable.

  • Registered Users

    ဟုတျအဈကို ဒီလိုလေးပဲလုပျလိုကျတော့မယျနောျ အဈကို။ကြေးဇူးပါအဈ ဟီး နောက်မ မုန့်ဝယ်ကွေျးတော့မယ် ဟီး

          SqlDataReader reader = sh.ExecuteReader(MyGlobalVariable.con_string, CommandType.Text, "SELECT authorid,authorname FROM authors");
                while (reader.Read())
                {
                    int row = dgvAuthor.Rows.Add();
                    dgvAuthor.Rows[row].Tag = reader["authorid"];
                    dgvAuthor.Rows[row].Cells[colAuthorName.Index].Value = reader["authorname"];
                }
    
  • Registered Users

    You should not write UI and DataAccess in the same layer.

Sign In or Register to comment.