|
|
|
C# WinApp มานำเสนอโค้ด การ ค้นหาข้อมูลใน DataGridView ครับ |
|
|
|
|
|
|
|
Code (C#)
#region _HaveValue
public static bool HaveValue(this System.Windows.Forms.DataGridView dgv, string cri)
{
bool b = false;
foreach (System.Windows.Forms.DataGridViewRow row in dgv.Rows)
{
if (row.Cells[row.Index].Value.ToString().Equals(cri))
{
dgv.Rows[row.Index].Selected = true;
b = true;
break;
}
}
return b;
}
public static bool HaveValue(this System.Windows.Forms.DataGridView dgv,int Column_0, string cri)
{
bool b = false;
for (int i = 0; i < dgv.RowCount - 1; i++)
{
if (dgv[Column_0,i].Value.ToString().Equals(cri))
{
dgv.Rows[i].Selected = true;
b = true;
break;
}
}
return b;
}
public static bool HaveValue(this System.Windows.Forms.DataGridView dgv, int Column_0, int Column_1, string cri)
{
bool b = false;
for (int i = 0; i < dgv.RowCount - 1; i++)
{
if (dgv[Column_0, i].Value.ToString().Equals(cri) && dgv[Column_1, i].Value.ToString().Equals(cri))
{
dgv.Rows[i].Selected = true;
b = true;
break;
}
}
return b;
}
public static bool HaveValue(this System.Windows.Forms.DataGridView dgv, int Column_0, string cri_0, int Column_1, string cri_1)
{
bool b = false;
for (int i = 0; i < dgv.RowCount - 1; i++)
{
if (dgv[Column_0, i].Value.ToString().Equals(cri_0) && dgv[Column_1, i].Value.ToString().Equals(cri_1))
{
dgv.Rows[i].Selected = true;
b = true;
break;
}
}
return b;
}
public static bool HaveValue(this System.Windows.Forms.DataGridView dgv, int Column_0, int Column_1, int Column_2, string cri)
{
bool b = false;
for (int i = 0; i < dgv.RowCount - 1; i++)
{
if (dgv[Column_0, i].Value.ToString().Equals(cri) && dgv[Column_1, i].Value.ToString().Equals(cri) && dgv[Column_2, i].Value.ToString().Equals(cri))
{
dgv.Rows[i].Selected = true;
b = true;
break;
}
}
return b;
}
public static bool HaveValue(this System.Windows.Forms.DataGridView dgv, int Column_0, string cri_0, int Column_1, string cri_1, int Column_2, string cri_2)
{
bool b = false;
for (int i = 0; i < dgv.RowCount - 1; i++)
{
if (dgv[Column_0, i].Value.ToString().Equals(cri_0) && dgv[Column_1, i].Value.ToString().Equals(cri_1) && dgv[Column_2, i].Value.ToString().Equals(cri_2))
{
dgv.Rows[i].Selected = true;
b = true;
break;
}
}
return b;
}
public static bool HaveValue(this System.Windows.Forms.DataGridView dgv, List<int> lColumn, string cri)
{
bool b = false;
for (int i = 0; i < dgv.RowCount - 1; i++)
{
for (int ii = 0; ii < lColumn.Count; ii++)
{
if (dgv[lColumn[ii], i].Value.ToString().Equals(cri))
{
dgv.Rows[i].Selected = true;
b = true;
break;
}
}
}
return b;
}
public static bool HaveValue(this System.Windows.Forms.DataGridView dgv, List<int> lColumn, List<string> lCri)
{
bool b = false;
for (int i = 0; i < dgv.RowCount - 1; i++)
{
for (int ii = 0; ii < lColumn.Count; ii++)
{
if (dgv[lColumn[ii], i].Value.ToString().Equals(lCri[ii]))
{
dgv.Rows[i].Selected = true;
b = true;
break;
}
}
}
return b;
}
#endregion
วิธีใช้ก็แค่ เช็ค ข้อมูลใน DataGridView เช่น ผมอยากเช็คว่ามี ข้อมูล MethodID SampleTypeID ParameterID ใน DataGridView รึปล่าว ถ้าไม่มีก็ Insert ข้อมูลลงใน dataset ครับ
Code (C#)
private void toolStripButton1_Click(object sender, EventArgs e)
{
frmProduct_Method_Detail_Addmulti f = new frmProduct_Method_Detail_Addmulti();
f.ShowDialog();
if (f.ListIndex == null) return;
if (f.ListIndex.Count <= 0) return;
Cursor.Current = Cursors.WaitCursor;
for(int i = 0;i<f.ListIndex.Count;i++)
{
if (!method_ParameterDataGridView.HaveValue(1, Method_ID.ToString(),
2,f.SampletypeID.ToString(),3,f.ListIndex[i].ToString()))
method_ParameterTableAdapter.Insert(Method_ID, f.SampletypeID, f.ListIndex[i], "", "", "", "", "", false, null, "", "", "", "", "", "", "", Class.UserLogin.EmployeeName, DateTime.Now);
}
Cursor.Current = Cursors.Default;
this.method_ParameterTableAdapter.Fill(this.dS_Product.Method_Parameter);
}
สะดวกในการเช็คข้อมูลก่อนที่จะ Insert ข้อมูลลง database ครับ
Tag : .NET, Win (Windows App), C#, VS 2012 (.NET 4.x)
|
|
|
|
|
|
Date :
2018-09-05 15:24:46 |
By :
lamaka.tor |
View :
759 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2018-09-05 15:48:36 |
By :
fonfire |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Source Code ของคุณมันยอดเยี่ยมก็จริง แต่คุณก็ไม่เคยเห็นของจริงค้นหาหลักร้อยล้านพันหมื่นล้านแสน ล้านระเบียน
ล้าหลังไปเมื่อสองร้อยปีที่แล้ว
|
|
|
|
|
Date :
2018-09-06 22:33:21 |
By :
หน้าฮี |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|