I have a list of CheckBoxes and after clicking on them the state is not updated.
Why is this happening and how can I repair this?
private List<CheckBox> blocks_check_boxes = new List<CheckBox>();
count = blocks_from_database.Count;
/* Display check boxes for each block*/
for (int i = 0; i < blocks_from_database.Count; i++)
{
blocks_check_boxes.Add(new CheckBox());
this.blocks_check_boxes[i].AutoSize = true;
this.blocks_check_boxes[i].Name = blocks_from_database[i].name;
this.blocks_check_boxes[i].Size = new System.Drawing.Size(80, 17);
this.blocks_check_boxes[i].TabIndex = 3 + i;
this.blocks_check_boxes[i].Text = blocks_from_database[i].name;
this.blocks_check_boxes[i].UseVisualStyleBackColor = true;
this.blocks_check_boxes[i].AutoCheck = true;
}
Thank you
Maybe you are recreating the CheckBoxes in an unwanted way.
Maybe you want to set the "AutoPostBack" property till "true".
It's pretty hard to understand what's causing your problem when we don't see more code. Explain a little more when you are detecting your problem and also where and when your code above is executing.
Related
I have a code in C# with 26 button in it and I want them to all be disabled until the user does something, but I dont want to copy/paste button1.Enable = false; Button2.Enable = false...
So is there a way to do something like this :
for (int i = 1; i < 26; i++)
{
button+i.Enable = false;
}
Thanks for your help.
You probably want to iterate buttons directly.
foreach(var button in this.Controls.OfType<Button>())
{
button.Enable = false;
}
Using either of Controls.Find or Controls.OfType<Button>() only works at run-time. I prefer a statically checkable compile-time approach. Then if you delete a button on the form the code won't compile. Helps give you that type-safe feeling.
I do it this way. Start with a field to hold the buttons in an array:
private Button[] _buttons = null;
Set the array once in your initialization code:
_buttons = new[] { button1, button2, button26 };
Then when you need to do something with the buttons you just do this:
foreach (var button in _buttons)
{
button.Enable = false;
}
You can use Form.Controls.Find()
for (int i = 1; i < 26; i++)
{
this.Controls.Find("button" + i, searchAllChildren: false).Enable = false;
}
The code assumes your buttons are named button1 through button26.
It's not possible directly like you are, but that doesn't make sense anyway.
I use Telerik GridView in winform Project.
this is my code:
this.radGridView1.EnableHotTracking = true;
this.radGridView1.ShowFilteringRow = true;
this.radGridView1.EnableFiltering = true;
this.radGridView1.EnableCustomFiltering = true;
DataTable table1 = new DataTable("Deducations");
table1.Columns.Add("R1");
table1.Columns.Add("R2");
table1.Columns.Add("R3");
Random rnd = new Random();
for (int i = 0; i < 100; i++)
{
DataRow row = table1.NewRow();
row[0] = rnd.Next(26, 360);
row[1] = rnd.Next(36, 460);
row[2] = rnd.Next(46, 560);
table1.Rows.Add(row);
}
radGridView1.DataSource = table1;
Filtering row is showing But, not working.
It'd be helpful if you could elaborate a bit more about your issues rather than just say something didn't work.
Anyway I'd say it might be worth looking at this line of code.
this.radGridView1.EnableCustomFiltering = true;
Above line indicates that you've enabled the Custom Filtering feature in the grid control, which means you have to write code to handle the custom filtering event yourself.
this.radGridView1.CustomFiltering += new GridViewCustomFilteringEventHandler(radGridView1_CustomFiltering);
private void radGridView1_CustomFiltering(object sender, GridViewCustomFilteringEventArgs e)
{
// your code...
}
Have you implemented this event? If you have, could you perhaps show us the code and let us know if any errors has occurred in it?
But if you don't need to use Custom Filtering, then just disable it or remove the line. All you need is the following two lines to enable the basic filtering feature.
this.radGridView1.EnableFiltering = true;
this.radGridView1.MasterTemplate.EnableFiltering = true;
Also take a look at following links. I hope you find them helpful too.
http://docs.telerik.com/devtools/winforms/gridview/filtering/basic-filtering
http://docs.telerik.com/devtools/winforms/gridview/filtering/custom-filtering
I have very strange problem in Visual Studio. I created grid on my windows form with 10 columns.
Everything works fine until I reordered the columns - all columns disappear!
I click undo, it gives back to me only 6 columns.
When I want to add 4 columns that are missing, the program throw error: This column already exist(or something like that). Then I have to get the latest version (I checked in before) to get all columns back. When I change anything in grid, same error happens every time. I tried to delete grid and make new one - same error. I even tried to delete WF and make new one - same error.
Any idea why is this happening?
Any idea how to reorder columns in code and bypass this strange error?
Best way is to control the code and not the same assistant you are doing.
To do this use the following example:
if (dataGridView1.DataSource != null)
{
dataGridView1.Columns["idColumn1"].HeaderText = "Text 1";
dataGridView1.Columns["idColumn1"].Width = 60;
dataGridView1.Columns["idColumn1"].Index = 0;
dataGridView1.Columns["idColumn2"].HeaderText = "Text 2";
dataGridView1.Columns["idColumn2"].Width = 60;
dataGridView1.Columns["idColumn2"].Index = 1;
dataGridView1.Columns["idColumn3"].HeaderText = "Text 3";
dataGridView1.Columns["idColumn3"].Width = 60;
dataGridView1.Columns["idColumn3"].Index = 2;
dataGridView1.Columns["idColumn4"].Visible= false;
dataGridView1.Columns["idColumn5"].Visible= false;
dataGridView1.Columns["idColumn6"].Visible= false;
}
I know that the main problem is not resolved, but if somebody have same error, you can reorder your columns in code like this:
private void TransakcijaZaFakturisanje_Load(object sender, EventArgs e)
{
gridTransakcijaZaFakturisanje.Columns["SifraTransakcije"].DisplayIndex = 0;
gridTransakcijaZaFakturisanje.Columns["Opis"].DisplayIndex = 1;
gridTransakcijaZaFakturisanje.Columns["SifraKomitenta"].DisplayIndex = 2;
gridTransakcijaZaFakturisanje.Columns["IdUgovor"].DisplayIndex = 3;
gridTransakcijaZaFakturisanje.Columns["IdUsluga"].DisplayIndex = 4;
gridTransakcijaZaFakturisanje.Columns["VaziOd"].DisplayIndex = 5;
gridTransakcijaZaFakturisanje.Columns["VaziDo"].DisplayIndex = 6;
//and so on...
}
I will continue to research the problem, if I find something usefull I will type it here. Thank you all for your support!
In my application, I have a DataGridView that moves from one Tab Control to another Tab Control.
I am doing this by changing its parent. This works with no problems on the first move from the origional Tab Control to the new one, but when changing the parent back to the origional, the DataGridView shows up (all the Columns are visible) but there is no data in the view.
I have tried to reload the data into the DataGridView, and refresh/Invalidate the control to make it redraw, but it still shows up empty. However, when the control goes back to the secondary parent, the data is back.
I am also using this exact code for another DataGridView and it works without any problems at all.
Any ideas would be greatly appreciated, and thanks in advance.
From Origional to Secondary
gvwRFIs.Parent = tabProcessingRFI; //Working
gvwConsentInfoMemos.Parent = tabProcessingMemos; //Working
From Secondary to Origional
gvwRFIs.Parent = tabConsentInfoRFI; //Empty Data
gvwConsentInfoMemos.Parent = tabConsentInfoMemos; //Working
RFI DataGridView Designer Code
//
// gvwRFIs
//
this.gvwRFIs.AllowUserToAddRows = false;
this.gvwRFIs.AllowUserToDeleteRows = false;
this.gvwRFIs.AllowUserToResizeRows = false;
this.gvwRFIs.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders;
this.gvwRFIs.BackgroundColor = System.Drawing.Color.White;
this.gvwRFIs.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.gvwRFIs.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.gvwID,
this.gvwType,
this.gvwSeq,
this.gvwCreated,
this.gvwProcessor,
this.gvwLetter,
this.gvwResponded,
this.gvwS,
this.gvwDetails});
this.gvwRFIs.Dock = System.Windows.Forms.DockStyle.Fill;
this.gvwRFIs.Location = new System.Drawing.Point(3, 3);
this.gvwRFIs.MultiSelect = false;
this.gvwRFIs.Name = "gvwRFIs";
this.gvwRFIs.ReadOnly = true;
this.gvwRFIs.RowHeadersVisible = false;
this.gvwRFIs.RowHeadersWidth = 4;
this.gvwRFIs.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.gvwRFIs.Size = new System.Drawing.Size(1078, 422);
this.gvwRFIs.TabIndex = 4;
this.gvwRFIs.DoubleClick += new System.EventHandler(this.gvwRFIs_DoubleClick);
Consent Tab Control Designer Code
//
// tabConsentInfoRFI
//
this.tabConsentInfoRFI.Controls.Add(this.gvwRFIs);
this.tabConsentInfoRFI.Controls.Add(this.lvwConsentInfoRFI);
this.tabConsentInfoRFI.Location = new System.Drawing.Point(4, 32);
this.tabConsentInfoRFI.Name = "tabConsentInfoRFI";
this.tabConsentInfoRFI.Padding = new System.Windows.Forms.Padding(3);
this.tabConsentInfoRFI.Size = new System.Drawing.Size(1084, 428);
this.tabConsentInfoRFI.TabIndex = 4;
this.tabConsentInfoRFI.Text = "RFI\'s";
this.tabConsentInfoRFI.UseVisualStyleBackColor = true;
Processing Tab Control Designer Code
//
// tabProcessingRFI
//
this.tabProcessingRFI.Location = new System.Drawing.Point(4, 36);
this.tabProcessingRFI.Name = "tabProcessingRFI";
this.tabProcessingRFI.Padding = new System.Windows.Forms.Padding(3);
this.tabProcessingRFI.Size = new System.Drawing.Size(868, 465);
this.tabProcessingRFI.TabIndex = 1;
this.tabProcessingRFI.Text = "RFI";
this.tabProcessingRFI.UseVisualStyleBackColor = true;
I found the issue,
The ListView that is in the consent designer code, is an old control that looks identical, but is no longer used. So when the control is parented back to the Origional tab, it is in the background of this control.
Once the control was removed (thought it already was) the code worked perfectly.
Thank you to LarsTech for getting me in the right direction. And akhisp for there answer.
You should remove the object from the Tab.Controls list of the tab that it's no longer in. So do something like:
tabProcessingRFI.Controls.Remove(gvwRFIs);
gvwRFIs.Parent = tabConsentInfoRFI
In a Web Part for Sharepoint, I'm trying to add a variable number/ordering of ButtonColumns to a DataGrid dynamically based on an option the user has selected. The problem is that the dynamic columns aren't firing off the events I set up on the DataGrid (such as SelectedIndexChanged). When the table originally constained a static set of columns, they were created in CreateChildControls() and everything worked peachy. However, since they are now dynamic, I have to delay adding them until after a search button's click event fires. I was wondering if there was some place I needed to move the column creation to that still allowed it to be dynamic but also allowed it to register/fire events.
outputDG creation in CreateChildControls():
outputDG = new System.Web.UI.WebControls.DataGrid();
outputDG.CellPadding = 4;
outputDG.HeaderStyle.Font.Bold = false;
outputDG.HeaderStyle.Font.Name = "Verdana";
outputDG.HeaderStyle.BackColor = Color.FromArgb(242,242,242);
outputDG.HeaderStyle.ForeColor = Color.FromArgb(128,128,128);
outputDG.HeaderStyle.Wrap = false;
//outputDG.ItemStyle.BorderColor = Color.Navy;
outputDG.HorizontalAlign = HorizontalAlign.Left;
//outputDG.BorderWidth = 1;
outputDG.GridLines = GridLines.Horizontal;
outputDG.Width = propsMgr.SearchGridWidth;
outputDG.PageSize = 10;
outputDG.AllowPaging = true;
outputDG.PagerStyle.Mode = PagerMode.NumericPages;
outputDG.PagerStyle.PageButtonCount = 5;
outputDG.PagerStyle.NextPageText = "Next Page";
outputDG.PagerStyle.PrevPageText = "Previous Page";
outputDG.PagerStyle.Visible = true;
outputDG.PageIndexChanged += new DataGridPageChangedEventHandler(this.outputDG_PageIndexChanged);
outputDG.AllowSorting = false;
outputDG.SortCommand += new DataGridSortCommandEventHandler(this.outputDG_SortCommand);
outputDG.SelectedItemStyle.BackColor = Color.FromArgb(255,244,206);
outputDG.SelectedIndexChanged += new EventHandler(this.outputDG_SelectedIndexChanged);
outputDG.ItemCreated += new DataGridItemEventHandler(this.outputDG_ItemCreated);
outputDG.AutoGenerateColumns = false;
outputDG.ItemCommand += new DataGridCommandEventHandler(outputDG_ItemCommand);
Controls.Add(outputDG);
During the search button's click event:
ButtonColumn buttonColumnSelect = new ButtonColumn();
buttonColumnSelect.ButtonType = ButtonColumnType.LinkButton;
buttonColumnSelect.CommandName = "Select";
buttonColumnSelect.HeaderText = "Column";
buttonColumnSelect.DataTextField = "columnField";
outputDG.Columns.Add(buttonColumnSelect);
And then later on it that same event I go through the result set and add in my data rows. Like I mentioned, this all worked back when the ButtomColumn code was up in CreateChildControls(), but it stopped working as soon as it was moved into an event. My best guess is that the event for the column doesn't have a chance to register in order to fire since it's happening from a different event. If I need to tackle this problem by building up the DataGrid differently, I'm definitely willing; I just need to be able to dynamically specify different columns to use.
maybe u need to set the ID-Attribute on the DataGrid.
otherwise it would be difficult for asp to find your control.
The fix for my case was to move the adding of the columns to the page's load event and the adding of the DataGrid to the controls after all of the columns are added.