过滤组合框中的值 [英] filter the values in the combobox

查看:51
本文介绍了过滤组合框中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个组合框'交易对手'和一个表'商品交易'。在表格中,我有两列交易对手和相关的合约状态列给该交易对手。有6种不同的合同状态。现在,我希望我的交易对手组合框只能解除与两个合约状态相关的那些值。我怎么能这样做?



  ///  连接数据库并获取交易对手数据
///
/// < param name =gasDay > < / param >
///
public DataTable GetCounterpartyInfos(DateTime gasDay)
{
try
{
DataTable dt = new DataTable( Counterparty);

使用 var context = ConnectionManager.GetManager(Database.Gms))
{
使用(SqlCommand fetchCommand =
context.Connection.CreateCommand( dbo.upCmp_Select_LU))
{
fetchCommand.Parameters.Add( @ GasDay
SqlDbType.DateTime).Value = gasDay;
fetchCommand.Parameters.Add( @ DBFunction
SqlDbType.VarChar ).Value = 提名;

SqlDataAdapter ta = new SqlDataAdapter(fetchCommand);
ta.Fill(dt);
}
}
return dt;
}
catch (例外情况)
{
throw FoundationAgent.CreateFoundationExceptionWrapper(
new FoundationException( 例外在GetCounterpartyInfos(),ex),ex);
}
}

解决方案

我认为您要做的是根据DataTable来归档行关于一栏的价值。

但是,你不能轻易地解释你的愿望。你真的需要提供更多的信息。

我现在只是猜测这就是你想做的事。



你可以做到这一点在c#代码:

  //  创建一个表格两列 
DataTable dt = new DataTable( 食品);
dt.Columns.Add( 名称);
dt.Columns.Add( Type);

dt.Rows.Add( Apple Fruit);
dt.Rows.Add( Carrot 蔬菜);
dt.Rows.Add( Pear Fruit);
dt.Rows.Add( Cucumber 蔬菜);
dt.Rows.Add( Tomato Fruit);
dt.Rows.Add( Broccoli 蔬菜);

// 创建DataView
DataView dv = new DataView(dt);

// 过滤水果
dv.RowFilter = Type ='Fruit';





然后使用 DataView 作为您的 DataSource 组合框


I've a combobox 'counterparty' and a table 'commodity trades'. In the table , i've two columns 'counterparty' and associated 'contract status' column to that counterparty. There are 6 different contract statuses. Now , I want my counterparty combobox to dsiplay only those values which are associated with two contract statuses. How can I do this?

/// Connects to database and gets counterparty data
/// 
/// <param name="gasDay"></param>
/// 
public DataTable GetCounterpartyInfos(DateTime gasDay)
{
    try
    {
      DataTable dt = new DataTable("Counterparty");
     
      using (var context = ConnectionManager.GetManager(Database.Gms))
      {
        using (SqlCommand fetchCommand =
          context.Connection.CreateCommand("dbo.upCmp_Select_LU"))
        {
          fetchCommand.Parameters.Add("@GasDay", 
             SqlDbType.DateTime).Value = gasDay;
          fetchCommand.Parameters.Add("@DBFunction", 
             SqlDbType.VarChar).Value = "Nominations";
     
          SqlDataAdapter ta = new SqlDataAdapter(fetchCommand);
          ta.Fill(dt);
        }
      }
      return dt;
    }
    catch (Exception ex)
    {
      throw FoundationAgent.CreateFoundationExceptionWrapper(
      new FoundationException("Exception is in GetCounterpartyInfos()", ex), ex);
    }
}

解决方案

I think what you want to do is to filer the rows in the DataTable depending on the value of one column.
You don't make it easy to interpret your wish, though. You really need to provide more information.
I am just guessing now that this is what you want to do.

You can do this in c# code:

// Create a table with two columns
DataTable dt = new DataTable("Food");
dt.Columns.Add("Name");
dt.Columns.Add("Type");

dt.Rows.Add("Apple", "Fruit");
dt.Rows.Add("Carrot", "Vegetable");
dt.Rows.Add("Pear", "Fruit");
dt.Rows.Add("Cucumber", "Vegetable");
dt.Rows.Add("Tomato", "Fruit");
dt.Rows.Add("Broccoli", "Vegetable");

// Create a DataView
DataView dv = new DataView(dt);

// Filter out the fruits
dv.RowFilter = "Type = 'Fruit'";



Then use the DataView as the DataSource for your ComboBox.


这篇关于过滤组合框中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆