|
|
|
รบกวนช่วยดูให้หน่อยค่ะ datagridviewcomboBoxColumn ทุกครั้งที่คลิก ปุ่ม submit มันจะเบิ้ลเพิ่มขึ้นเรื่อยๆ ค่ะ |
|
|
|
|
|
|
|
เวลาที่คลิกทีปุ่ม submit datagridviewcomboBoxColumn มันจะเบิ้ลเพิ่มขึ้นเรื่อยๆ อ่ะค่ะ
ต้องแก้ไขยังไงคะ ไม่ให้มันเบิ้ลเพิ่มขึี้นเรื่อยๆ
Code (C#)
private void ShowGrid() {
string year = DateTime.Now.ToString("yyyy", new System.Globalization.CultureInfo("en-US"));
DalBillTruck d = new DalBillTruck();
string sql_db = "SELECT KEBillTruck.DocDate, KEBillTruck.DocNo, KEBillTruck.CarCode, KEBillTruck.CarCodeSub, KECustomer.Name1 AS CustName, " ;
sql_db += " KEItem.Name1 AS ItemName,KEBillTruck.CreateCode, KEBillTruck.CreateDateTime, KEBillTruck.LastEditorCode, KEBillTruck.LastEditDateT, ";
sql_db +=" KEBillTruck.IsRefund, KEBillTruck.TripType,KEBillTruck.WayCode, KEBillTruck.KM, KEBillTruck.RateUp, KEBillTruck.RateDown, " ;
sql_db +=" KEItem.GroupCode FROM KEBillTruck INNER JOIN KEItem ON KEBillTruck.ItemCode = KEItem.Code INNER JOIN " ;
sql_db +=" KECustomer ON KEBillTruck.CustCode = KECustomer.Code " ;
sql_db += " WHERE (KEBillTruck.DocDate >= '" + DateConvert.DateNoTime(dateF.Value) + "' AND KEBillTruck.DocDate <= '" + DateConvert.DateNoTime(dateT.Value) + "' )";
sql_db += " AND (KEItem.Code = 'p44081' OR KEItem.Code = 'J44070' OR KEItem.Code = 'F44064' OR KEItem.Code = 'F44066') ";
if (txtSearchDocNo.TextLength != 0) { sql_db += " AND (KEBillTruck.DocNo like '%" + txtSearchDocNo.Text + "%' OR KEItem.Name1 like '%" + txtSearchDocNo.Text + "%') "; }
if (txtSearchCust.TextLength != 0) { sql_db += " AND (KECustomer.Name1 like '%" + txtSearchCust.Text + "%' OR KEBillTruck.CarCode like '%" + txtSearchCust.Text + "%') "; }
sql_db += " order by KEBillTruck.DocNo Desc";
try {
d.OpenbySql(sql_db);
dv = new DataView(d.DataTable);
} catch (Exception ex) {
Msg.MsgError(ex.Message);
return;
}
DataGridView1.DataSource = dv;// d.DataTable;
setHeadCol();
foreach (DataGridViewRow row in DataGridView1.Rows)
{
DataGridViewComboBoxCell cbCell = (DataGridViewComboBoxCell)row.Cells[11];
cbCell.Value = row.Cells["TripType"].Value;
if (row.Cells["TripType"].Value.ToString() == "-1" || row.Cells["TripType"].Value.ToString() == null)
{
row.Cells["colType"].Value = 0;
}
}
lblCount.Text = "รวมรายการ : " + d.Count;
}
int intCol = 0;
DataGridViewComboBoxColumn colType;
private void DataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
DataGridView1.Columns["TripType"].Visible = false;
DalBillTruck dd = new DalBillTruck();
string sql = "SELECT tranID, tran_name FROM KETran";
try
{
dd.OpenbySql(sql);
dv2 = new DataView(dd.DataTable);
}
catch (Exception ex)
{
Msg.MsgError(ex.Message);
return;
}
BindingSource BindSource = new BindingSource();
BindSource.DataSource = dv2;
if (intCol == 0)
{
if (DataGridView1.Rows.Count != 0)
{
colType = new DataGridViewComboBoxColumn();
colType.HeaderText = "colType";
colType.DataSource = BindSource;
colType.ValueMember = "tranID";
colType.DisplayMember = "tran_name";
colType.Width = 100;
colType.Name = "colType";
colType.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
DataGridView1.Columns.Insert(11,colType);
}
//intCol++;
}
}
Tag : .NET, Ms SQL Server 2008, Win (Windows App), Windows
|
ประวัติการแก้ไข 2014-10-31 14:13:29
|
|
|
|
|
Date :
2014-10-31 14:12:39 |
By :
K927 |
View :
828 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DataGridView1.Columns.Insert(11,colType); แสดงว่าทุกครั้งที่ เรียกใช้งาน private void DataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
ก็จะเพิ่ม colType เสมอครับ
|
|
|
|
|
Date :
2014-10-31 15:53:22 |
By :
lamaka.tor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|