Home > Net >  Want to work in the datagridview state this a "win" in the column of all data, the ratio o
Want to work in the datagridview state this a "win" in the column of all data, the ratio o

Time:09-21



State, there are five new, advice, validation, win, dynamic data in datagridview now, want to "win" on the data of all, the ratio of specific code guidance, thank you!

CodePudding user response:

Simple cycle count?

The datagridview. Cells [I, 2] value judgment

CodePudding user response:

Can get the number of business opportunities, in the event of an GridView1_RowDataBound or traverse the gridview GridView1_RowDataBound event all lines

CodePudding user response:

refer to the second floor stami response:
can get the number of business opportunities, in the event of an GridView1_RowDataBound or traverse the gridview GridView1_RowDataBound event all rows


Iterate through all the line after my formula how to write, please guide, thank you!

CodePudding user response:

Can write in your "query statements" click event, the list to the datagridview binding data, such as datagridview1. The DataSource=dt;

 
Double I=dataGridView1. Rows. Count;

IEnumerable EnumerableList=this. DataGridView1. Rows. Cast (a);
List List=(from item in enumerableList
Where the item. The Cells [2]. The Value. The ToString ()=="win"
Select the item). ToList ();

Double j=list Count;
String rate=(j/I * 100) ToString (" F2 ");


This rate is what you need to display the value of the I and j is defined as a double in order to accurately display and don't have to convert,

CodePudding user response:

Loved the
reference 4 floor response:
can write in your "query statements" click event, list to the datagridview binding data, such as datagridview1. The DataSource=dt;

 
Double I=dataGridView1. Rows. Count;

IEnumerable EnumerableList=this. DataGridView1. Rows. Cast (a);
List List=(from item in enumerableList
Where the item. The Cells [2]. The Value. The ToString ()=="win"
Select the item). ToList ();

Double j=list Count;
String rate=(j/I * 100) ToString (" F2 ");


This rate is what you need to display the value of the I and j is defined as a double in order to accurately display and don't have to convert,


And then I showed him directly in the text box txt_sjcgl. Text==rate. The Tostring () is it

CodePudding user response:

String s="win";
Int sCnt=0;
Int rowCnt=datagridview. Rows. Count;

for (int i=0; i{
If (datagridview [2] I==s)
{
SCnt +=1;
}
}

Success=sCnt/rowCnt * 100;

CodePudding user response:

If the DatagridView backend binding is a DataTable,
Then use the DataTable Select method can filter out the number of
Sample:
 
//according to the filter for filtering
DataRow [] rows=dt. Select (" state='win' ");
If (dt. Rows. Count & gt; 0)
Float thewire=rows. Count/dt. Rows. Count;
  •  Tags:  
  • C#
  • Related