我遇到了一些麻煩我的頁面上有一個datagridview,其數據源不斷變化基於從2組合框, 對值檢索記錄我需要添加一個複選框列到我的DataGrid中,這與從我的數據庫表中的任何列中沒有數據綁定,我使用這個代碼我在添加複選框列在我的datagridview
public void RefreshDataGrid(string query)
{
Buisness_logic bl = new Buisness_logic();
dataGridView1.DataSource = bl.GetDataTable(query);
SetUpDataGridView();
dataGridView1.ClearSelection();
}
public void SetUpDataGridView()
{
DataGridViewCellStyle style = dataGridView1.ColumnHeadersDefaultCellStyle;
style.BackColor = Color.White;
style.ForeColor = Color.Black;
dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;
dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
dataGridView1.RowHeadersVisible = false;
dataGridView1.Columns[0].HeaderText = "Sr.No";
dataGridView1.Columns[0].Width = 50;
dataGridView1.Columns[1].HeaderText = "Rate";
dataGridView1.Columns[1].Width = 70;
dataGridView1.Columns[2].HeaderText = "Amount";
dataGridView1.Columns[2].Width = 100;
dataGridView1.Columns[3].HeaderText = "Mode";
dataGridView1.Columns[3].Width = 60;
dataGridView1.Columns[4].HeaderText = "Support";
dataGridView1.Columns[4].Width = 80;
dataGridView1.Columns[5].HeaderText = "Team1";
dataGridView1.Columns[5].Width = 100;
dataGridView1.Columns[6].HeaderText = "Team2";
dataGridView1.Columns[6].Width = 100;
dataGridView1.Columns[7].HeaderText = "Team3";
dataGridView1.Columns[7].Width = 100;
DataGridViewCheckBoxColumn column3 = new DataGridViewCheckBoxColumn();
column3.Name = "Column3";
column3.HeaderText = "IsCheck";
column3.ReadOnly = false;
dataGridView1.Columns.Add(column3);
}
它的DataGridView是好當TGE形式加載的第一次,但是當我改變的價值組合框和數據源發生變化,列被搞砸了,沒有。的複選框列得到補充,並且毀了我的形式,
這裏是我用來從表中檢索記錄
Combo_pair pr1 = combo_match_code.SelectedItem as Combo_pair;
int match_code_f1 = Convert.ToInt32(pr1.Text);
Combo_pair pair = combo_name.SelectedItem as Combo_pair;
int userid_f1 = Convert.ToInt32(pair.Value);
string query = "Select int_sr_no,double_rate,double_amount,txt_mode,txt_support,double_team1,double_team2,double_team3 from match_transaction where int_match_code='" + match_code_f1 + "' AND int_user_id='" + userid_f1 + "' AND is_deleted=0";
RefreshDataGrid(query);
這是圖像的代碼加載窗體時首次
,這是圖像後,我改變了組合框值幾十倍
*(對不起,具有圖像麻煩) 我真的需要一些幫助這些,thanxx
對於每個組合框更改,您正在調用'SetUpDataGridView'?既然你添加了一個複選框列,它會繼續添加其被調用的次數。 – V4Vendetta 2012-07-12 06:17:52
所以我應該設置一個計數器,以便它只執行第一次?任何幫助如何計數器必須看起來像?遺憾與數據網格還挺新:( – 2012-07-12 06:23:45