DatagridView突出显示事件 - WINFORM C# [英] DatagridView Highlight Event - WINFORM C#

查看:149
本文介绍了DatagridView突出显示事件 - WINFORM C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接到数据库的组合框,所以我根据我的数据库中的内容填充了我的组合框的值。我的组合框是数据网格的另一个FORM。所以这里是我想要实现的。

I have a combobox which is connected to the database so I populate the value of my combobox based on what's in my database. my combobox is another FORM from the datagrid. So here's I want to achieve.

form1 = datagrid(基于数据库)
form2 =组合框(基于数据库)

form1 = datagrid (based on the database) form2 = combobox (based on the database)

我想要如果我突出显示某行(我的选择模式= fullrowselect),然后按一个按钮,组合框将自动指向该行。

I want that If I highlight a certain row (My selection mode = fullrowselect) and press a button the comboBox will automatically point to that row.

例如
datagrid

for ex. datagrid


  1. 名称:Joe(突出显示)

  2. *用户点击按钮在我的情况下是编辑

  3. *加载编辑表单

  4. comboBox.SelectedIndex is =突出显示的行(用户点击)

  1. name: Joe (highlighted)
  2. *user clicks the button whch in my case is edit
  3. *load edit form
  4. comboBox.SelectedIndex is = highlighted row (which the user clicks)

如果有帮助,我可以告诉你我的代码。谢谢:))

I can show you my code if it helps. thanks :))

谢谢! :))

推荐答案

您可以尝试以下列方式设置,您可以通过以下方法将值Joe传递给另一种形式参数在构造函数中。这可以用于在 ComboBox中选择您需要的值

You can try to set in the following ways, you can pass the value Joe to the other form via a parameter in the constructor. This could be then used to select you required value in the ComboBox

comboBox2.SelectedIndex = comboBox2.Items.IndexOf(Joe);

comboBox2.SelectedText =Three; //或SelectedValue取决于绑定的方式

comboBox2.SelectedText = "Three"; // or SelectedValue depending on how you are binding

编辑
避免直接从其他表单,公开所需的值作为属性或更好地将其传递给新表单作为参数。

EDIT Avoid accessing the grid directly from the other form, expose the value required as a property or better pass it to the new form as parameter.

Joe可以是像 dataGridView2.CurrentRow [0] .FormattedValue ,并将其传递给新的表单构造函数,如 new Form2(object datagridvalue)。然后在后面的表单中使用该值。

Joe could be the value of the cell like dataGridView2.CurrentRow[0].FormattedValue and pass this to the new form constructor like new Form2(object datagridvalue). Then use the value in the form later on.

这篇关于DatagridView突出显示事件 - WINFORM C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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