本文介绍了DataGridView SelectionChanged EVENT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



在我的表格上有两个datagridview:



一个datagridview被填充DataBinding:



Hello,

On my form a have two datagridview:

One datagridview is filled by DataBinding:

private void controlContractePrincipalLoad(object sender, EventArgs e)
       {
           string NumeClientCautat = txtCautaDupaNume.Text;
           this.sClienti.DataSource = SetariAmanet.TotiClienti(NumeClientCautat);
       }





一个CellContentClick EVENT(它的作品):





A CellContentClick EVENT (its works):

private void dVizualizareClientiCellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView vizualizare = sender as DataGridView;
            if (vizualizare != null)
            {
                IdClientSelectat = Convert.ToInt32(vizualizare.SelectedRows[0].Cells[0].Value.ToString());
                if (IdClientSelectat != 0)
                {
                    InformatiiDespreClientContracte();
                }
            }
        }





和SelectionChanged事件:





AND a SelectionChanged event:

private void dVizualizareClientiSelectionChanged(object sender, EventArgs e)
        {
            DataGridView vizualizare = sender as DataGridView;
            if (vizualizare != null)
            {
                IdClientSelectat = Convert.ToInt32(vizualizare.SelectedRows[0].Cells[0].Value.ToString());
                if (IdClientSelectat != 0)
                {
                    InformatiiDespreClientContracte();
                }
            }
        }





SelectionChanged事件不起作用

错误按摩是:索引超出范围。



SelectionChanged事件执行两次(我认为),我的IdClientSelectat第一次使用值,然后他在这一行给我一个错误:





The SelectionChanged event is not working
The error massage is: Index out of range.

The SelectionChanged event is executed two times (i think), the first time my IdClientSelectat hase a value, then he gives me an error at this line:

IdClientSelectat = Convert.ToInt32(vizualizare.SelectedRows[0].Cells[0].Value.ToString());





问题出在哪里?



Where is the problem?

推荐答案

if (vizualizare != null && vizualizare.Rows.Count > 0 && vizualizare.Columns.Count > 0)


这篇关于DataGridView SelectionChanged EVENT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 01:48