日期:2014-05-18  浏览次数:21083 次

DataGridViewComboBoxColumn数据填充问题
大家好,小弟刚学C#,现在遇到个数据填充的问题,图片如下:



如图,DataGridView中有一个ComboBox列,这一列的值取另一张表中的数据,代码如下:
请大家帮我看看出错在哪里:
C# code

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

namespace newbook
{
    public partial class Frm_publish : Form
    {
        public Frm_publish()
        {
            InitializeComponent();
        }
        SqlDataAdapter ADP = null;
        DataSet ds = new DataSet();
        private static string selectComm = "select a.pid,a.pub_id,a.pub_name,b.area_name as areaid,a.address from j_publishing a,j_area b where a.areaid=b.area_id";

        SqlDataAdapter ADP_combox = null;
        //DataSet ds_combox = new DataSet();
        private static string combox = "select area_id,area_name from j_area";

        private void Frm_publish_Load(object sender, EventArgs e)
        {
            try
            {
                ADP = new SqlDataAdapter(selectComm, operation.conn());
                ADP.Fill(ds, "publish");
                this.dataGridView1.DataSource = ds.Tables["publish"];

                ADP_combox = new SqlDataAdapter(combox, operation.conn());
                ADP_combox.Fill(ds, "combox");
                this.Column5.DataSource = ds.Tables["combox"];
                this.Column5.DisplayMember = "area_id";
                this.Column5.ValueMember = "area_name";
                
            }
            catch (DataException se)
            {
                MessageBox.Show(se.ToString());
            }
            
        }
    }
}




------解决方案--------------------
图片看不到
------解决方案--------------------
不知道,真的看不到啊
------解决方案--------------------
还是不可以,不知道是网络问题,我机器问题,还是
------解决方案--------------------
还是看不了,一样的提示,该图片仅限baidu用户交流使用
------解决方案--------------------
看不到图片。。。
------解决方案--------------------
DatagridViewComboxColumn cmbox = Datagridview.Columns["COmbox控件的Name"] as DatagridViewComboxColumn ; 

cmbox.DataSource = 下框的数据源; 
cmbox.DataPropertyName= datagrid的数据源的要绑定的列; 
cmbox.d...Member="下拉框显示的TEXT"; 
cmbox.ValueMember="隐藏的值"; 


DataGridViewComboBoxColumn csex = new DataGridViewComboBoxColumn(); 
csex.DataPropertyName = "sSex"; 
csex.HeaderText = "性别"; 
DataTable dt = new DataTable(); 
dt.Columns.Add("sexname"); 
dt.Columns.Add("sexvalue"); 
DataRow dr = dt.NewRow(); 
dr[0] = "男"; 
dr[1] = "1"; 
dt.Rows.Add(dr); 
DataRow dr1 = dt.NewRow(); 
dr1[0] = "女"; 
dr1[1] = "2"; 
dt.Rows.Add(dr1); 

csex.DataSource = dt; 
csex.ValueMember = "sexvalue"; 
csex.DisplayMember = "sexname"; 
this.datagridview1.Columns.Add(csex); 
http://topic.csdn.net/u/20091009/11/b0255b05-505a-4622-9402-0a8fb31f8575.html
------解决方案--------------------