我有一個DataGridView。我綁定與如下數據源的DataGridBiew ...如何防止DataGridView列增加
private void form_load(object sender, eventargs e)
{
var members = xyz.members(..
select new {
blah....
blahh...
});
memberbindingsource.datasource = members
membergridview1.datasource = memberbindingsource;
// at here i have added button column to membergridview 1
// like this....
DataGridViewButtonColumn column = new DataGridViewButtonColumn();
membergridview1.Columns.Add(column);
column.FlatStyle = FlatStyle.Standard;
column.DefaultCellStyle.BackColor = Color.Green;
column.Text = "ADD";
column.HeaderText = "Add";
column.UseColumnTextForButtonValue = true;
column.Name = "btnadd";
能正常工作的形式負載,但地方我檢查的條件在ComboBox這樣
if(combobox1.text == "abc")
{
then i have to loaded the grid view again
like this ...
var members = xyz.members(..
select new {
blah....
blahh...
});
memberbindingsource.datasource = members
membergridview1.datasource = memberbindingsource;
at here i have added button column to membergridview 1
like this....
DataGridViewButtonColumn column = new DataGridViewButtonColumn();
membergridview1.Columns.Add(column);
column.FlatStyle = FlatStyle.Standard;
column.DefaultCellStyle.BackColor = Color.Green;
column.Text = "ADD";
column.HeaderText = "Add";
column.UseColumnTextForButtonValue = true;
column.Name = "btnadd";
}
時,首先選擇combobox1文本「ABC」在DataGridView中顯示按鈕欄多數民衆贊成罰款...
當我檢查的第一conditon(這樣combobox1.text == "abc"
)在DataGridView顯示細節確定,但如果我再次檢查相同的條件下它會再次加butto n列。
我想顯示只有一個按鈕列與成員數據,當我一次又一次地檢查相同的條件。
我該如何防止這種情況 - 一次又一次增加按鈕列?
所以選擇從組合框中選擇一個項目應該添加新的專欄,但只有當它不存在?還是你問完全其他的東西? – hometoast
亞..我必須檢查這樣的條件多達6(條件)所以..每次我必須填充datagridview有沒有辦法我們可以對綁定源的操作我的意思是我可以使用相同的綁定源爲6(檢查)那樣... –
這很混亂。爲什麼每當組合框文本=「abc」時再次添加列?只要刪除重新添加列的代碼,如果你不想一遍又一遍地添加。 – kevev22