组合框列 [英] combobox column

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

问题描述

我在c#,2.0的datagridview中有2个combobox列.
如果我选择一个组合值,然后选择其他组合值,则第一个组合消失.实际上,在gridview上单击任何位置,组合框的值就会消失.. !!
谁能帮我,如何保留两个组合框的值?
请尽快回复.谢谢

代码:

I have 2 comboboxcolumns in datagridview in c#, 2.0.
if i select one combo value and then other combo value, the first one dissapears. infact clicking anywhere on the gridview, the combobox value dessapears..!
can any one help me, how to retain the values of both the comboboxes ?
Pls respond ASAP. Thank you

Code:

SqlCommand cmd = MyDatabase.sqlDbCmd;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Get_Units";
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.SelectCommand = cmd;
da.Fill(ds, "tbl");
dgvSim.DataSource = ds.Tables[0].DefaultView;
// Adding 1st combo column
DataGridViewComboBoxColumn comboboxColumn = new DataGridViewComboBoxColumn();
string strSqlQuery = "Exec Get_Sim -1";
SqlDataReader sqlTempReader = MyDatabase.GetDataReader(strSqlQuery);
while (sqlTempReader.Read())
{
    comboboxColumn.Items.Add(sqlTempReader["S_Id"].ToString());
    comboboxColumn.DisplayMember = sqlTempReader["S_Id"].ToString();
    comboboxColumn.ValueMember = sqlTempReader["S_Id"].ToString();
    comboboxColumn.DataPropertyName = sqlTempReader["S_Id"].ToString();
}
Davs_Database.CloseSQLConnection();
comboboxColumn.ValueType = typeof(String);
comboboxColumn.Visible = true;
comboboxColumn.HeaderText = "S Name";
dgvSim.Columns.Add(comboboxColumn);

//Adding 2nd combo column
DataGridViewComboBoxColumn comboboxColumnSimType = new DataGridViewComboBoxColumn();
comboboxColumnSimType.Items.AddRange("L","S","G","M","GA N");
comboboxColumnSimType.DisplayMember = comboboxColumnSimType.Items.ToString();
comboboxColumnSimType.ValueMember = comboboxColumnSimType.Items.ToString();
comboboxColumnSimType.DataPropertyName = comboboxColumnSimType.Items.ToString();
comboboxColumnSimType.Visible = true;
comboboxColumnSimType.HeaderText = "S Type";
comboboxColumnSimType.ValueType = typeof(String);
dgvSim.Columns.Add(comboboxColumnSimType);
            
//Adding link column.
DataGridViewLinkColumn links = new DataGridViewLinkColumn();
links.HeaderText = "";
links.Name = "Config";
links.DataPropertyName = "S_Id";
links.ActiveLinkColor = Color.White;
links.LinkBehavior = LinkBehavior.SystemDefault;
links.LinkColor = Color.Blue;
links.TrackVisitedState = true;
links.VisitedLinkColor = Color.BlueViolet;
links.UseColumnTextForLinkValue = true;
links.Text = "Config";
dgvSim.Columns.Add(links);
                      
dgvSim.Visible = true;

推荐答案

组合索引更改事件-或选择更改.

将值放在全局字段中.

当表单的refresh()或paint()执行时.在组合框上进行选择,或者选择一个selectedvalue()selectedtext()

做完后应该保留.

您有不定期的事件刷新了您以前的设置.

也可能是数据绑定问题.
combo index change event - or selection change.

put the values in global fields.

when the refresh() or paint() of the form executes. make the selection on the combobox or so a selectedvalue() selectedtext()

Should remain when yu done.

you have events that''s irregular that flushes your previous settings.

Could be a databinding issue as well.


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

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