Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > Default ข้อมูลลง ComBoBox in DataGridView แบบช่องของ สถานะ



 

Default ข้อมูลลง ComBoBox in DataGridView แบบช่องของ สถานะ

 



Topic : 119689



โพสกระทู้ ( 202 )
บทความ ( 0 )



สถานะออฟไลน์




คือผม มีสถานะอะครับ แต่ว่าจะเอาลง ใน datagridview ยังไงครับ พอ ดึงข้อมูลลงมา มันก็ ไม่โชว์ name โชว์ แต่ id คือผมอยากไห้โชว์ name ครับ
01

อันนี้โค๊ดที่ทำไว้ครับต้องแก้ไขยังไงมั่งครับ

Code (C#)
private void load_default()
        {
            if (conn.State == ConnectionState.Closed)
                conn.Open();
            string sql = "select * FROM receive_details JOIN receives ON receives.id=receive_details.receive_id join stock_incomings on stock_incomings.receive_detail_id=receive_details.id";
            SqlDataAdapter sda = new SqlDataAdapter(sql
            , conn); 
            DataTable dt = new DataTable();
            sda.Fill(dt);
            dataGridView1.Rows.Clear();

            sql = "select * from receives_types";
            sda = new SqlDataAdapter(sql, conn);
            sda.Fill(dt);
            i9.DisplayMember = "name";
            i9.ValueMember = "id";
            i9.DataSource = dt;
           
            foreach (DataRow item in dt.Rows)
            {
                int n = dataGridView1.Rows.Add();
                dataGridView1.Rows[n].Cells[0].Value = item["receive_no"].ToString();
                dataGridView1.Rows[n].Cells[1].Value = item["invoice_no"].ToString();
                dataGridView1.Rows[n].Cells[2].Value = item["product_code"].ToString();
                dataGridView1.Rows[n].Cells[3].Value = item["receive_id"].ToString();
                dataGridView1.Rows[n].Cells[4].Value = item["product_name"].ToString();
                dataGridView1.Rows[n].Cells[5].Value = item["product_unit_name"].ToString();
                dataGridView1.Rows[n].Cells[6].Value = item["remark"].ToString();
                dataGridView1.Rows[n].Cells[7].Value = item["quantity"].ToString();
                dataGridView1.Rows[n].Cells[8].Value = item["receive_type_id"].ToString();
            }

        } 




Tag : .NET, Ms SQL Server 2012, C#







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2015-11-02 14:26:51 By : phuriwat View : 1368 Reply : 12
 

 

No. 1



โพสกระทู้ ( 4,434 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ลองเชคดูว่าระบุ property ครบยังครับ

13212

https://www.thaicreate.com/community/csharp-datasource-wizard-datagridviewcomboboxcolumn.html






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-02 14:53:35 By : lamaka.tor
 


 

No. 2



โพสกระทู้ ( 202 )
บทความ ( 0 )



สถานะออฟไลน์


ผมก็ กำหนด แล้วนะครับ ตัวนี้อะครับ
Code (C#)
 sql = "select * from receives_types";
            sda = new SqlDataAdapter(sql, conn);
            sda.Fill(dt);
            i9.DisplayMember = "name";
            i9.ValueMember = "id";
            i9.DataSource = dt;

แต่มัน ไม่ได้อะครับ คือ ผมจะเอา receives_types ที่เป็น สถานะ อะครับ คือตอนแรกเก็บเป็น id 1 2 3 ไว้ แต่จะโชว์ เป็น name ยังไงครับ


ประวัติการแก้ไข
2015-11-02 15:10:37
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-02 15:07:06 By : phuriwat
 

 

No. 3



โพสกระทู้ ( 4,434 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

มีคำถามมาให้คิดเล่นๆ

Code (C#)
  foreach (DataRow item in dt.Rows)
            {
                int n = dataGridView1.Rows.Add();
                dataGridView1.Rows[n].Cells[0].Value = item["receive_no"].ToString();
                dataGridView1.Rows[n].Cells[1].Value = item["invoice_no"].ToString();
                dataGridView1.Rows[n].Cells[2].Value = item["product_code"].ToString();
                dataGridView1.Rows[n].Cells[3].Value = item["receive_id"].ToString();
                dataGridView1.Rows[n].Cells[4].Value = item["product_name"].ToString();
                dataGridView1.Rows[n].Cells[5].Value = item["product_unit_name"].ToString();
                dataGridView1.Rows[n].Cells[6].Value = item["remark"].ToString();
                dataGridView1.Rows[n].Cells[7].Value = item["quantity"].ToString();
                dataGridView1.Rows[n].Cells[8].Value = item["receive_type_id"].ToString();
            }


dt ที่ว่านี้มาจาก
sql = "select * from receives_types";

หรือ

sql = "select * FROM receive_details JOIN receives ON receives.id=receive_details.receive_id join stock_incomings on stock_incomings.receive_detail_id=receive_details.id";
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-02 15:21:56 By : lamaka.tor
 


 

No. 4



โพสกระทู้ ( 202 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 3 เขียนโดย : lamaka.tor เมื่อวันที่ 2015-11-02 15:21:56
รายละเอียดของการตอบ ::

มาจากอันล่างครับ




ประวัติการแก้ไข
2015-11-02 15:28:17
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-02 15:27:53 By : phuriwat
 


 

No. 5



โพสกระทู้ ( 4,434 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

Code (C#)
private void load_default()
        {
            if (conn.State == ConnectionState.Closed)
                conn.Open();
            string sql = "select * FROM receive_details JOIN receives ON receives.id=receive_details.receive_id join stock_incomings on stock_incomings.receive_detail_id=receive_details.id";
            SqlDataAdapter sda = new SqlDataAdapter(sql
            , conn); 
            DataTable dt = new DataTable();
            sda.Fill(dt);
            dataGridView1.Rows.Clear();

            sql = "select * from receives_types";
            sda = new SqlDataAdapter(sql, conn);
            sda.Fill(dt);//// dt ถูก set ค่าใหม่ 
            i9.DisplayMember = "name";
            i9.ValueMember = "id";
            i9.DataSource = dt; // dt น่าจะมาจาก sql = "select * from receives_types";
           
            foreach (DataRow item in dt.Rows) // dt น่าจะมาจาก sql = "select * from receives_types";
            {
                int n = dataGridView1.Rows.Add();
                dataGridView1.Rows[n].Cells[0].Value = item["receive_no"].ToString();
                dataGridView1.Rows[n].Cells[1].Value = item["invoice_no"].ToString();
                dataGridView1.Rows[n].Cells[2].Value = item["product_code"].ToString();
                dataGridView1.Rows[n].Cells[3].Value = item["receive_id"].ToString();
                dataGridView1.Rows[n].Cells[4].Value = item["product_name"].ToString();
                dataGridView1.Rows[n].Cells[5].Value = item["product_unit_name"].ToString();
                dataGridView1.Rows[n].Cells[6].Value = item["remark"].ToString();
                dataGridView1.Rows[n].Cells[7].Value = item["quantity"].ToString();
                dataGridView1.Rows[n].Cells[8].Value = item["receive_type_id"].ToString();
            }

        } 


มันเป็นแบบนั้นป่าวครับ
รึผมเดาผิด 555
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-02 15:37:58 By : lamaka.tor
 


 

No. 6



โพสกระทู้ ( 4,434 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

DataTable แบบบ้านๆมาฝากใช้ง่ายไม่งงดี

Code (C#)
private DataTable Table(String SQL)
        {
            if (conn.State == ConnectionState.Closed)
                conn.Open();
            SqlDataAdapter sda = new SqlDataAdapter(SQL, conn); 
            DataTable dt = new DataTable();
            sda.Fill(dt);
            Return dt;
       }


ใช้งาน

Code (C#)
dataGridView1.DataSource = Table("select * FROM receive_details JOIN receives ON receives.id=receive_details.receive_id join stock_incomings on stock_incomings.receive_detail_id=receive_details.id");

i9.DataSource = Table("select * from receives_types");

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-02 15:44:20 By : lamaka.tor
 


 

No. 7



โพสกระทู้ ( 202 )
บทความ ( 0 )



สถานะออฟไลน์


คือตอนแรก อะครับ
Code (C#)
"select * FROM receive_details JOIN receives ON receives.id=receive_details.receive_id join stock_incomings on stock_incomings.receive_detail_id=receive_details.id"

3ตารางนี้จะมี receive_type_id อยู่ครับ ซึ่งเป็น status ครับ ถ้าเอาลงมาเก็บไว่ใน columntext มันจะเป็นตัวเลขอะครับ
แต่ถ้าจะเอาไว้ใน datagridcombobox แบบ มาถึงก็ โหลดลงมาเลยอะครับ เช่นถ้า id เป็น 1 ก็จะโชว์ปกติ 2 ก็จะล็อก ไรงี้อะครับ
ส่วนอันนี้
Code (C#)
"select * from receives_types"

คือผมจะไห้มันไป เอาว่า id 1 คืออะไร 2 คืออะไรอ่ะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-02 15:55:11 By : phuriwat
 


 

No. 8



โพสกระทู้ ( 4,434 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ประเด็นคือ

foreach (DataRow item in dt.Rows) // dt น่าจะมาจาก sql = "select * from receives_types";

ไม่ได้มาจาก

"select * FROM receive_details JOIN receives ON receives.id=receive_details.receive_id join stock_incomings on stock_incomings.receive_detail_id=receive_details.id"

ครับ
sql = "select * from receives_types";
sda = new SqlDataAdapter(sql, conn);
sda.Fill(dt);//// dt ถูก set ค่าใหม่

ลองเขียนใหม่ดูๆๆ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-02 16:01:29 By : lamaka.tor
 


 

No. 9



โพสกระทู้ ( 202 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 8 เขียนโดย : lamaka.tor เมื่อวันที่ 2015-11-02 16:01:29
รายละเอียดของการตอบ ::
อันนี้คือตอนแรกเลยอะครับ แล้วจะไห้ช่องที่สีแดงเป็น combobox แล้วโชว์ status ของมันยังไง อะครับ
Code (C#)
private void load_default()
        {
            if (conn.State == ConnectionState.Closed)
                conn.Open();
            string sql = "select * FROM receive_details JOIN receives ON receives.id=receive_details.receive_id join stock_incomings on stock_incomings.receive_detail_id=receive_details.id";
            SqlDataAdapter sda = new SqlDataAdapter(sql
            , conn); 
            DataTable dt = new DataTable();
            sda.Fill(dt);
            dataGridView1.Rows.Clear();                     
           
            foreach (DataRow item in dt.Rows)
            {
                int n = dataGridView1.Rows.Add();
                dataGridView1.Rows[n].Cells[0].Value = item["receive_no"].ToString();
                dataGridView1.Rows[n].Cells[1].Value = item["invoice_no"].ToString();
                dataGridView1.Rows[n].Cells[2].Value = item["product_code"].ToString();
                dataGridView1.Rows[n].Cells[3].Value = item["receive_id"].ToString();
                dataGridView1.Rows[n].Cells[4].Value = item["product_name"].ToString();
                dataGridView1.Rows[n].Cells[5].Value = item["product_unit_name"].ToString();
                dataGridView1.Rows[n].Cells[6].Value = item["remark"].ToString();
                dataGridView1.Rows[n].Cells[7].Value = item["quantity"].ToString();
                dataGridView1.Rows[n].Cells[8].Value = item["receive_type_id"].ToString();
            }

        } 


1


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-02 16:15:46 By : phuriwat
 


 

No. 10



โพสกระทู้ ( 4,434 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

https://www.thaicreate.com/community/csharp-datasource-wizard-datagridviewcomboboxcolumn.html

ง่ายดีครับ

แต่ถ้าอยากเขียนเป็นโค้ดก็

Code (C#)
this.dataGridViewTextBoxColumn1.DataPropertyName = "PostCodeID";
            this.dataGridViewTextBoxColumn1.HeaderText = "PostCodeID";
            this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
            // 
            // dataGridViewTextBoxColumn2
            // 
            this.dataGridViewTextBoxColumn2.DataPropertyName = "PostCode";
            this.dataGridViewTextBoxColumn2.HeaderText = "PostCode";
            this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2";
            // 
            // dataGridViewTextBoxColumn3
            // 
            this.dataGridViewTextBoxColumn3.DataPropertyName = "Pnv";
            this.dataGridViewTextBoxColumn3.DataSource = this.sett_Post_ProvinceBindingSource;
            this.dataGridViewTextBoxColumn3.DisplayMember = "Province";
            this.dataGridViewTextBoxColumn3.HeaderText = "Pnv";
            this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3";
            this.dataGridViewTextBoxColumn3.Resizable = System.Windows.Forms.DataGridViewTriState.True;
            this.dataGridViewTextBoxColumn3.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.dataGridViewTextBoxColumn3.ValueMember = "pvnID";
            // 
            // dataGridViewTextBoxColumn4
            // 
            this.dataGridViewTextBoxColumn4.DataPropertyName = "Amp";
            this.dataGridViewTextBoxColumn4.HeaderText = "Amp";
            this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4";
            // 
            // dataGridViewTextBoxColumn5
            // 
            this.dataGridViewTextBoxColumn5.DataPropertyName = "PosOff";
            this.dataGridViewTextBoxColumn5.HeaderText = "PosOff";
            this.dataGridViewTextBoxColumn5.Name = "dataGridViewTextBoxColumn5";
            // 
            // dataGridViewTextBoxColumn6
            // 
            this.dataGridViewTextBoxColumn6.DataPropertyName = "Note";
            this.dataGridViewTextBoxColumn6.HeaderText = "Note";
            this.dataGridViewTextBoxColumn6.Name = "dataGridViewTextBoxColumn6";


            this.sett_Post_PostCodeDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.dataGridViewTextBoxColumn1,
            this.dataGridViewTextBoxColumn2,
            this.dataGridViewTextBoxColumn3,
            this.dataGridViewTextBoxColumn4,
            this.dataGridViewTextBoxColumn5,
            this.dataGridViewTextBoxColumn6});
            this.sett_Post_PostCodeDataGridView.DataSource = this.sett_Post_PostCodeBindingSource;

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-02 17:13:09 By : lamaka.tor
 


 

No. 11



โพสกระทู้ ( 4,434 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

น่าจะประมาณนี้ครับ
Code (C#)
private DataTable GetTable(String SQL)
        {
            if (conn.State == ConnectionState.Closed)
                conn.Open();
            SqlDataAdapter sda = new SqlDataAdapter(SQL, conn); 
            DataTable dt = new DataTable();
            sda.Fill(dt);
            Return dt;
       }



Code (C#)
// Set Column
            DataGridViewTextBoxColumn c1 = new DataGridViewTextBoxColumn() { DataPropertyName = "receive_no", HeaderText = "receive_no" };
            DataGridViewTextBoxColumn c2 = new DataGridViewTextBoxColumn() { DataPropertyName = "invoice_no", HeaderText = "invoice_no" };
            DataGridViewTextBoxColumn c3 = new DataGridViewTextBoxColumn() { DataPropertyName = "product_code", HeaderText = "product_code" };
            DataGridViewTextBoxColumn c4 = new DataGridViewTextBoxColumn() { DataPropertyName = "receive_id", HeaderText = "receive_id" };
            DataGridViewTextBoxColumn c5 = new DataGridViewTextBoxColumn() { DataPropertyName = "product_name", HeaderText = "product_name" };
            DataGridViewTextBoxColumn c6 = new DataGridViewTextBoxColumn() { DataPropertyName = "product_unit_name", HeaderText = "product_unit_name" };
            DataGridViewTextBoxColumn c7 = new DataGridViewTextBoxColumn() { DataPropertyName = "remark", HeaderText = "remark" };
            DataGridViewTextBoxColumn c8 = new DataGridViewTextBoxColumn() { DataPropertyName = "quantity", HeaderText = "quantity" };
            DataGridViewComboBoxColumn c9 = new DataGridViewComboBoxColumn() { DataPropertyName = "receive_type_id", HeaderText = "receive_type_id", DataSource = GetTable(select * from receives_types), DisplayMember = "name", ValueMember = "id" };

// Add Column
            dataGridView1.Columns.AddRange(c1,c2,c3,c4,c5,c6,c7,c8,c9);
// Set DataSource 
            dataGridView1.DataSource =GetTable (select * FROM receive_details JOIN receives ON receives.id=receive_details.receive_id join stock_incomings on stock_incomings.receive_detail_id=receive_details.id);



บ้านไก็น่าจะประมาณนี้ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-02 17:25:41 By : lamaka.tor
 


 

No. 12



โพสกระทู้ ( 202 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 11 เขียนโดย : lamaka.tor เมื่อวันที่ 2015-11-02 17:25:41
รายละเอียดของการตอบ ::
ได้แล้วครับ ขอบคุณครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-03 14:11:05 By : phuriwat
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : Default ข้อมูลลง ComBoBox in DataGridView แบบช่องของ สถานะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่