在我的datagridview
中,四列1 & 2是隻讀列3 & 4得到了數字值。我想比較一下,第4列必須大於第3列。 例如:比較datagridview中的2個不同列
如果第4列值小於第3列,然後我想提議消息不導航到另一個控制。
我的簡單方法似乎不起作用。我怎樣才能比較2種特定的列這種情況?
private void datagridview_CellValidating(object sender, CellValidatingEventArgs e)
{
try
{
int bbor = datagridview.CurrentCell.ColumnIndex;
int ebor = datagridview.CurrentCell.RowIndex;
if (ebor <= bbor)
{
MessageBox.Show("Please verify the value");
e.Cancel = true;
}
}
catch (Exception exception)
{
}
}
你爲什麼要比較的行和列的索引?從適當位置的每個單元格中獲取值並比較值,而不是索引。 –
在某些情況下,在datagridview中它可能有8行,我無法比較每一行。 BY排行索引可能會更好..如果我錯了,請糾正我。謝謝你; – linguini
我編輯了你的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 –