本文介绍了在运行时选择DataGridViewCombobox单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

您好,专家,

更改datagridviewcombobox单元格选择的任何想法在窗体加载时(即在运行时).DatagridViewCombobox单元格在设计时填充为Grant和Denied的数据.我想根据从数据库检索的参数显示已授予"或已拒绝".

注意:这是Windows应用程序.

在这方面的任何帮助将不胜感激.

问候,
Kartheesh

Hi Experts,

Any idea to change the selection of datagridviewcombobox cell On form load(i.e at runtime).DatagridViewCombobox cell is filled with data as Granted and Denied at design time. I wanted to display Granted or Denied based on parameters retrieved from database.

Note: This is windows application.

Any help in this regard would be appreciated.

Regards,
Kartheesh

推荐答案

<asp:DropDownList ID="ddl1" runat="server" DataSourceID="SqlDataSource1" DataValueField="Status" AutoPostBack="True" SelectedValue='<%# Convert.ToInt32(Eval("Denied")) == 1? "1":"0" %>' >
    </asp:DropDownList>



我认为这可以解决您的问题
Anurag



I think, this would solve your problem
Anurag



// Create ComboBox Column in DataGridView
DataGridViewComboBoxColumn dgvcmb=new DataGridViewComboBoxColumn();
dgvcmb.DisplayMember = "Name";
dgvcmb.ValueMember= "Id";
dgvcmb.DataSource= dtData.Copy();
dataGridView1.Controls.Add(dgvcmb);

// Get Selected Value from that ComboBox
private void dataGridView1_EditingControlShowing(object sender,
  DataGridViewEditingControlShowingEventArgs e)
  {
  if (dataGridView1.CurrentCell.ColumnIndex >= 0)
  {
      ComboBox cmbBox= e.Control as ComboBox;
      cmbBox.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged);
 }
  }

  void comboBox_SelectedIndexChanged(object sender, EventArgs e)
  {
   if(((ComboBox)sender).SelectedValue != null)
   {
    string sId =((ComboBox)sender).SelectedValue.ToString();
    string sName =((ComboBox)sender).Text.ToString();
   }
  }




请参阅此代码,它将对您有所帮助.

干杯:)




Refer this code,its will helpful to you.

Cheers :)


这篇关于在运行时选择DataGridViewCombobox单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 07:55