Label value not set on ComboBox's SelectedIndexChanged (only in one case) - c#

This is possibly the strangest (and possibly most simple) error I have come across. I have a ComboBox with 3 items. Based on the selected index I set the visibility of 3 PictureBoxes and a Label's text. The problem is with the latter:
private void myCombo_SelectedIndexChanged(object sender, EventArgs e)
{
switch (myCombo.SelectedIndex)
{
case 0: // basic
pictureBoxBasicCampaign.Visible = true;
pictureBoxApsisCampaign.Visible = false;
pictureBoxPushCampaign.Visible = false;
lblCampaignTypeDescription.Text = "Runs or schedules a campaign that writes the recipient data into a file or another database table.";
break;
case 1: // apsis
pictureBoxBasicCampaign.Visible = false;
pictureBoxApsisCampaign.Visible = true;
pictureBoxPushCampaign.Visible = false;
lblCampaignTypeDescription.Text = "Runs or schedules a campaign that sends a newsletter or SMS message to recipients via APSIS.";
break;
case 2: // push
pictureBoxBasicCampaign.Visible = false;
pictureBoxApsisCampaign.Visible = false;
pictureBoxPushCampaign.Visible = true;
lblCampaignTypeDescription.Text = "Runs or schedules a campaign that sends a push notification to devices running an iOS or Android app.";
break;
}
}
Everything works fine! But my lblCampaignTypeDescription's text is not changed ONLY when SelectedIndex is 0 and I get an empty label. No exception is thrown and my debug traverses over the lblCampaignTypeDescription.Text. But no text. Case 1 and 2 display the text correctly.
Has anyone ever had this issue? Or have I done something stupid?
Update:
All references to lblCampaignTypeDescription in my project:
private MetroFramework.Controls.MetroLabel lblCampaignTypeDescription;
this.lblCampaignTypeDescription = new MetroFramework.Controls.MetroLabel();
this.metroTabPageSelectType.Controls.Add(this.lblCampaignTypeDescription);
//
// lblCampaignTypeDescription
//
this.lblCampaignTypeDescription.FontSize = MetroFramework.MetroLabelSize.Small;
this.lblCampaignTypeDescription.FontWeight = MetroFramework.MetroLabelWeight.Regular;
this.lblCampaignTypeDescription.Location = new System.Drawing.Point(121, 261);
this.lblCampaignTypeDescription.Name = "lblCampaignTypeDescription";
this.lblCampaignTypeDescription.Size = new System.Drawing.Size(700, 18);
this.lblCampaignTypeDescription.Style = MetroFramework.MetroColorStyle.Silver;
this.lblCampaignTypeDescription.TabIndex = 11;
this.lblCampaignTypeDescription.Text = "campaign_type_description";
this.lblCampaignTypeDescription.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.lblCampaignTypeDescription.Theme = MetroFramework.MetroThemeStyle.Light;
this.lblCampaignTypeDescription.UseStyleColors = true;
The label is a custom label control from MetroFramework Winform UI library. But I have been using it a million times and this it the first time this is happening.

When your SelectedIndex changes from 1 to 0 or from 2 to 0 does your lblCampaignTypeDescription.Text changes?Try to show the selectedIndex before other actions.It should be -1 i think

Related

RichTextBox Multi-Line Color (Partial Line Color Only)

I am having an issue retaining multi-line color in a RichTextBox control.
Issue: When appending new messages to the RichTextBox control and the message needs to be painted a certain color, all messages prior to the new message are painted a gray color and remain that way.
Question: How do I only paint the messages that need to be painted, when they are appended.
I have a status update event fired from a background thread that adds the status and message for that update to a List<StatusEventArgs>. Then, I clear my RichTextBox control and begin adding the updates to it. I should probably move this to just append the text instead of clearing it every time and rebuilding it; however, I did this in an attempt to retain color. The messages are a form of log that is represented to the user so they know what is currently happening during this long running process. For example:
1. Running process.
2. Starting something.
3. Doing something else.
4. Doing something. SUCCESS.
5. Doing something. SUCCESS.
6. Doing something. SUCCESS.
7. Doing something. FAIL. Attempting to continue.
8. Doing some other thing.
9. Complete.
In the example above, lines 4 - 7 have additional appended text such as SUCCESS. The beginning of these lines should be the normal Color.Black color for the RichTextBox control. The appended message SUCCESS should be colored based on the Status supplied for that message. So for example, lines 4 and 6 say SUCCESS and were received with a successful status. Line 5 says success but encountered a warning or minor issue and was received with a warning status. Line 7 was received with an error status. As you will see in the code supplied below, each status has it's own color associated with it. The text prior to that status on the same line should remain the Color.Black color.
Important Note
The message and its status are sent separately, this is due to each operation taking different amounts of time, thus the user should know that a process is happening and so far there hasn't been a status report from that process.
Current Code
private List<StatusEventArgs> events = new List<StatusEventArgs>();
private void StatusUpdate(object sender, StatusEventArgs e) {
events.Add(e);
rtb.Text = string.Empty;
foreach (StatusEventArgs sea in events) {
Status s = sea.Status;
rtb.SelectionStart = rtbConsole.TextLength;
rtb.SelectionLength = 0;
rtb.SelectionColor = rtbConsole.ForeColor;
if (s == UpdateStatus.Error || s == UpdateStatus.Warning || s == UpdateStatus.Success) {
rtb.Text = rtb.Text.TrimEnd('\n');
rtb.SelectionStart = rtbConsole.TextLength;
rtb.SelectionLength = 0;
switch (s) {
case Status.Error: rtb.SelectionColor = Color.DarkRed; break;
case Status.Warning: rtb.SelectionColor = Color.DarkGoldenrod; break;
case Status.Success: rtb.SelectionColor = Color.DarkGreen; break;
}
}
rtb.AppendText($"{sea.Message}\n");
}
rtb.ScrollToCaret();
}
Dependencies
public enum UpdateStatus { NoOperation, Error, Warning, Success }
public class StatusEventArgs {
public UpdateStatus Status { get; set; }
public string Message { get; set; }
}
I have looked at several of the related questions here on StackOverflow and (this one) is the closest to what I need; however, the post recommends selecting text in a specific range, which still did not work. It did the exact same thing my current code does. Keep in mind, I did not have the loop or list of events when I implemented the answer. I also cant utilize the recommendation to paint specific text in the RichTextBox because as I stated in the example above, the SUCCESS message can have two different colors depending on if warnings are received or not.
Attempt Code
int previousLength = rtb.TextLength;
UpdateStatus s = e.Status;
bool status = s == UpdateStatus.Error || s == UpdateStatus.Warning || s == UpdateStatus.Success;
if (status)
rtb.Text = rtb.Text.TrimEnd('\n');
rtb.AppendText($"{e.Message}\n");
rtb.ScrollToCaret();
if (status) {
rtb.Select(previousLength, rtb.TextLength);
switch (s) {
case Status.Error: rtb.SelectionColor = Color.DarkRed; break;
case Status.Warning: rtb.SelectionColor = Color.DarkGoldenrod; break;
case Status.Success: rtb.SelectionColor = Color.DarkGreen; break;
}
rtb.Select(0, 0);
}
I honestly feel like I am just missing a step or needing to do something just a little different. Recoloring all status messages each time a new status message is received seems like a bit much for such a trivial task.
Update
I tested the Dictionary<int[], UpdateStatus> method and it works the way I need it to; however, I believe this is quite over the top for something so simple:
private Dictionary<int[], UpdateStatus> selections = new Dictionary<int[], UpdateStatus>();
private void StatusUpdate(object sender, StatusEventArgs e) {
int previousLength = rtbConsole.TextLength;
UpdateStatus s = e.Status;
bool status = s != UpdateStatus.NoOperation;
if (status)
rtb.Text = rtb.Text.TrimEnd('\n');
rtb.AppendText($"{e.Message}\n");
rtb.ScrollToCaret();
if (status)
selections.Add(new int[] { previousLength, rtb.TextLength }, s);
// Set all basic text to black.
rtb.Select(0, rtb.TextLength);
rtb.SelectionColor = Color.Black;
// Color all status messages.
foreach (int[] selection in selections.Keys) {
rtb.Select(selection[0], selection[1]);
switch (selections[selection])
case Status.Error: rtb.SelectionColor = Color.DarkRed; break;
case Status.Warning: rtb.SelectionColor = Color.DarkGoldenrod; break;
case Status.Success: rtb.SelectionColor = Color.DarkGreen; break;
}
// Prevent messages in-between status messages from being colored.
rtb.Select(selection[1], rtb.TextLength);
rtb.SelectionColor = Color.Black;
}
}
Update 2
This is my implementation of LarsTech's post below. It still paints everything prior to the current status message black:
UpdateStatus s = e.Status;
if (s != UpdateStatus.NoOperation)
rtb.Text = rtb.Text.TrimEnd('\n');
Color textColor = Color.Black;
switch (selections[selection]) {
case Status.Error: textColor = Color.DarkRed; break;
case Status.Warning: textColor = Color.DarkGoldenrod; break;
case Status.Success: textColor = Color.DarkGreen; break;
}
rtb.Select(rtb.TextLength, 0);
rtb.SelectionColor = textColor;
rtb.AppendText($"{e.Message}\n");
rtb.ScrollToCaret();
Update 3
So the Update 2 method above works, the issue is the following line of code:
rtb.Text = rtb.Text.TrimEnd('\n');
This line of code causes the entire control to remove all current formatting Which makes me wonder, if I wanted to keep the formatting I already had, should I use the Rtf property? I suppose I'll try that and find out. Per MSDN:
The Text property does not return any information about the formatting applied to the contents of the RichTextBox. To get the rich text formatting (RTF) codes, use the Rtf property. The amount of text that can be entered in the RichTextBox control is limited only by available system memory.
Final Update
The Rtf property did not work in my case (simply swapped rtb.Text to rtb.Rtf. Tried a couple other ways but none worked. However, for those who (like me) are passing in a straight message and appending a new line as you print it, you can take the approach of prefixed new line. Then you can add some logic to prevent it when it shouldn't be there. This removes the need for TrimEnd and thus the accepted answer will work just fine:
// Field
bool firstUpdate = true;
private void StatusUpdate(...) {
UpdateStatus s = e.Status;
Color textColor = Color.Black;
switch (selections[selection]) {
case Status.Error: textColor = Color.DarkRed; break;
case Status.Warning: textColor = Color.DarkGoldenrod; break;
case Status.Success: textColor = Color.DarkGreen; break;
}
string newline = firstUpdate || s != Status.NoOperation ? string.Empty : "\n";
rtb.Select(rtb.TextLength, 0);
rtb.SelectionColor = textColor;
rtb.AppendText($"{newline}{e.Message}");
rtb.ScrollToCaret();
if (firstUpdate)
firstUpdate = false;
}
The issue is caused by replacing the string in the Text property:
rtb.Text = rtb.Text.TrimEnd('\n');
This line of code causes the entire control to remove all current formatting Per MSDN:
The Text property does not return any information about the formatting applied to the contents of the RichTextBox. To get the rich text formatting (RTF) codes, use the Rtf property. The amount of text that can be entered in the RichTextBox control is limited only by available system memory.
Otherwise, the code can be simplified to just:
Color textColor = Color.Black;
switch (e.Status) {
case Status.Error: textColor = Color.DarkRed; break;
case Status.Warning: textColor = Color.DarkGoldenrod; break;
case Status.Success: textColor = Color.DarkGreen; break;
}
rtb.Select(rtb.TextLength, 0);
rtb.SelectionColor = textColor;
rtb.AppendText($"{e.Message}\n");
rtb.ScrollToCaret();

Invoke a Jquery function from a webbrowser

I am trying to get a data from a password protected webpage using webbrowser , which uses a div container with 3 JQuery data fields. The 2nd field depends on the 1st one, and the 3rd one of the 2nd one.I need to set those 3 comboboxes and hit submit in order to get the data I want to scrape. The problem is that once the 1st combobox changes, it invokes a function which populates the 2nd and 3rd boxes. I can't figure out how to invoke this function...
This is how the first combobox looks like:
Select s[DCOM1] Selection1
I managed to set the 1st combobox, however the big problem that I have is to invoke viewStep.onSChanged() , which supposed to populate the 2nd box, I just can't make it work.
The onSChanged function is located in a Jquery js. file
self.onsChanged = function(selectadj) {
self.viewBasicsUpdated = true;
log.debug('onsChanged');
if (self.s) {
self.adjEnabled = false;
self.adj = null;
self.auctionType = 'S';
controller.ds.getadjList(self.s.id, function(response) {
controller.applyUpdates(function() {
self.adjList = response.data;
// Add "Add adj" option (as first in array).
self.adjList.unshift({
id : ADD_adj_ID,
fullName : controller.locale.getMessage('app.label.add.adj')
});
self.adjEnabled = true;
self.standardEnabled = true;
self.vixEnabled = (StringUtils.trimWS(self.s.vixFlag) === 'Y') ? true : false;
self.offsiteEnabled = (StringUtils.trimWS(self.s.offsiteFlag) === 'Y') ? true : false;
self.titOnlyEnabled = (StringUtils.trimWS(self.s.titOnlyFlag) === 'Y') ? true : false;
self.salType = self.s.salType;
self.titProcurementFlag = (StringUtils.trimWS(self.s.titProcurmentFlag) === 'Y') ? true : false;
//Selects the adj when a new adj is added.
if(selectadj){
angular.forEach(self.adjList, function(object, index) {
log.debug("object.id++"+object.id);
if(object.id===self.newadjId){
self.adj=object;
log.debug("self.newadjId++"+object.id);
}
});
}
});
});
}else{
controller.applyUpdates(function() {
self.adj = null;
self.adjEnabled = false;
self.auctionType = 'S';
self.standardEnabled = false;
self.vixEnabled = false;
self.offsiteEnabled = false;
self.titOnlyEnabled = false;
self.salType = null;
self.titProcurementFlag = false;
});`
}
};
I have tried to invoke the function in many different options including invokescript, posting an identical post request as the one I see with Fiddler (I guess it fails since the cookie is different) but everything fails. Is there a way to execute this function?
When setting values on input controls with Javascript the DOM events might not fire, depending on how the values are set.
Instead of trying to execute the very same function that the webpage would normally trigger, in this case self.onsChanged, fire the event on the control that you updated.
$("#selectBox1").val("Value A");
$("#selectBox1").change();
https://api.jquery.com/change/

Text property for text box is not displaying its value

I have a list of objects that I'm adding to.
private List<Employee> employees = new List<Employee>();
I have a button on my form application to create a new employee object and add it to the list. Prior to clicking it, it displays "Add Hourly Employee". After clicking it, it changes to "Save Hourly Employee". I'm just using a boolean to determine what text to display.
private void addHrlyEmpBtn_Click(object sender, EventArgs e)
{
resetBtn.Enabled = true;
cancelBtn.Enabled = true;
if (!addHourly)
{
resetBtn.Enabled = true;
cancelBtn.Enabled = true;
textBox4.Enabled = false;
textBox4.Text = (employees.Count + 1).ToString();
textBox7.Enabled = false;
addHrlyEmpBtn.Text = "Save Hourly Employee";
}
else if (addHourly)
{
//Grab values, create new object, and add to list.
//Set addHourly to false;
}
//Other stuff
}
I'm trying to display employees.Count + 1 to textBox4, but for some reason it isn't working. No text is being displayed at all. Idealy, I'd like to have the text box disabled but still display the value. And I only want it to display when !addHourly.
Am I doing something wrong?
There's nothing wrong in principal with the code you wrote.
I would strongly suggest giving meaningful names to all of your variables. Names like textBox4 are likely to cause confusion for yourself and future maintainers of the code.
If the value is not changing as you expect, you are most likely not entering that if branch.
Set a breakpoint at
if (!addHourly)
See if addHourly has the value you expect.
Check if addHrlyEmpBtn_Click is being called at all.
if it isn't try associating the Click event with addHrlyEmpBtn_Click method from the designer
or add addHrlyEmpBtn.Click += addHrlyEmpBtn_Click; in the constructor

Why does auto Zoom/Scroll not work for my Chart?

to make it short I checked on the "WinFormsChartSamples" provided by Microsoft. What I wanted to know is how to enable zooming and scrolling for Chartcontrols. The example which is shown there is pretty short.
using System.Windows.Forms.DataVisualization.Charting;
...
// Set automatic zooming
chart1.ChartAreas["Default"].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas["Default"].AxisY.ScaleView.Zoomable = true;
// Set automatic scrolling
chart1.ChartAreas["Default"].CursorX.AutoScroll = true;
chart1.ChartAreas["Default"].CursorY.AutoScroll = true;
...
I tried this and nothing happened, no zooming and no scrolling. I tried two things:
In Form1.Designer.cs I added that information to the chart.
chartArea1.Name = "ChartArea1";
chartArea1.CursorX.AutoScroll = true;
chartArea1.CursorY.AutoScroll = true;
chartArea1.AxisX.ScaleView.Zoomable = true;
chartArea1.AxisY.ScaleView.Zoomable = true;
this.chart1.ChartAreas.Add(chartArea1);
this.chart1.Cursor = System.Windows.Forms.Cursors.Cross;
legend1.Name = "Legend1";
this.chart1.Legends.Add(legend1);
this.chart1.Location = new System.Drawing.Point(297, 62);
this.chart1.Name = "chart1";
series1.ChartArea = "ChartArea1";
series1.Legend = "Legend1";
series1.Name = "Series1";
this.chart1.Series.Add(series1);
this.chart1.Size = new System.Drawing.Size(963, 668);
this.chart1.TabIndex = 6;
this.chart1.Text = "chart1";
I tried to add it directly into the constructor in Form1.cs.
Perhaps it is important to mention that I am using OpenFileDialog in order to add data to the series:
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
Stream fileStream = null;
OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "Open File..";
//First the description of the file separated by "|"
fDialog.Filter = "((ASC files)| *.asc";
fDialog.InitialDirectory = #"C:\";
//Show Messagebox if the file was loaded (Source: MSDN - FileDialog.FilterProperty)
if (fDialog.ShowDialog() == DialogResult.OK)
{
MessageBox.Show("The File was loaded successfully.");
try
{
if ((fileStream = fDialog.OpenFile()) != null)
{
using (fileStream)
{
//Insert code for reading the stream here.
Spectrum newSpectrum = new Spectrum(chart1.Series.Count, fDialog.FileName,
fDialog.SafeFileName, DataHandler.readSpectrumFromFile(fileStream));
addSpectrumToView(newSpectrum);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Any advice is welcome, thanks in advance,
BC++
I think you were actually really looking for this:
chart1.ChartAreas["Default"].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas["Default"].CursorY.IsUserSelectionEnabled = true;
used in conjunction with what you already have should work well, which should look like this:
// Set automatic zooming
chart1.ChartAreas["Default"].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas["Default"].AxisY.ScaleView.Zoomable = true;
// Set automatic scrolling
chart1.ChartAreas["Default"].CursorX.AutoScroll = true;
chart1.ChartAreas["Default"].CursorY.AutoScroll = true;
// Allow user selection for Zoom
chart1.ChartAreas["Default"].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas["Default"].CursorY.IsUserSelectionEnabled = true;
Have a look here: http://archive.msdn.microsoft.com/mschart There is an example there which does zooming/scrolling and much, much more! :)
To enable easy zooming, add a trackbar and use it to zoom:
private void trackBar1_Scroll(object sender, EventArgs e)
{
chart1.ChartAreas[0].AxisX.ScaleView.Size = trackBar1.Maximum - trackBar1.Value;
chart1.ChartAreas[1].AxisX.ScaleView.Size = trackBar1.Maximum - trackBar1.Value;
(etc for however many chart areas you have)
}
the "maximium - value" is to so that the higher the trackbar value, the fewer points are shown (closer zoom)
and make sure that in designer the 'chart1->ChartAreas->Axes->(whichever axes)->scaleview->zoomable' is set to true
A scroll bar will normally appear when a datapoint exceeds the scaleview size of an axis, if it has been set (scrolling doesn't really work reliably if left at 'auto'), if it hasn't, set it, if a scrollbar doesn't appear, a trackbar can yet again be used:
private void trackBar2_ValueChanged(object sender, EventArgs e)
{
chart1.ChartAreas[0].AxisX.ScaleView.Position = trackBar2.Value;
chart1.ChartAreas[1].AxisX.ScaleView.Position = trackBar2.Value;
(etc for however many chart areas you have)
}
Make sure you set the "Maximum" in the trackbars to a nice high number (eg 5000) and "Value" to what you desire it to load at.
Have yet to notice too much of a difference between "trackBar_Scroll" and "trackBar_ValueChanged", except "ValueChanged" works if the trackbar is moved by the program or user mouse click, whereas "Scoll" only works if moved by users mouse click.
Anything I missed?
My users dislikes the standard behavior of the mschart zooming and scrolling. That's why I implement a mouse based zoom/scroll that use dragging and mousewheel on axises.
The source code is here: https://bitbucket.org/controlbreak/mschartfriend
It is very simple and short, you can change it very quickly if you need.

Data table columns become out of order after changing data source

This is kind of a oddball problem so I will try to describe the best that I can.
I have a DataGridView that shows a list of contracts and various pieces of information about them. There are three view modes: Contract Approval, Pre-Production, and Production. Each mode has it's own set of columns that need to be displayed.
What I have been doing is I have three radio buttons one for each contract style. all of them fire their check changed on this function
private void rbContracts_CheckedChanged(object sender, EventArgs e)
{
dgvContracts.Columns.Clear();
if (((RadioButton)sender).Checked == true)
{
if (sender == rbPreProduction)
{
dgvContracts.Columns.AddRange(searchSettings.GetPreProductionColumns());
this.contractsBindingSource.DataMember = "Preproduction";
this.preproductionTableAdapter.Fill(this.searchDialogDataSet.Preproduction);
}
else if (sender == rbProduction)
{
dgvContracts.Columns.AddRange(searchSettings.GetProductionColumns());
this.contractsBindingSource.DataMember = "Production";
this.productionTableAdapter.Fill(this.searchDialogDataSet.Production);
}
else if (sender == rbContracts)
{
dgvContracts.Columns.AddRange(searchSettings.GetContractsColumns());
this.contractsBindingSource.DataMember = "Contracts";
this.contractsTableAdapter.Fill(this.searchDialogDataSet.Contracts);
}
}
}
Here is the GetxxxColumns function
public DataGridViewColumn[] GetPreProductionColumns()
{
this.dgvTxtPreAccount.Visible = DgvTxtPreAccountVisable;
this.dgvTxtPreImpromedAccNum.Visible = DgvTxtPreImpromedAccNumVisable;
this.dgvTxtPreCreateDate.Visible = DgvTxtPreCreateDateVisable;
this.dgvTxtPreCurrentSoftware.Visible = DgvTxtPreCurrentSoftwareVisable;
this.dgvTxtPreConversionRequired.Visible = DgvTxtPreConversionRequiredVisable;
this.dgvTxtPreConversionLevel.Visible = DgvTxtPreConversionLevelVisable;
this.dgvTxtPreProgrammer.Visible = DgvTxtPreProgrammerVisable;
this.dgvCbxPreEdge.Visible = DgvCbxPreEdgeVisable;
this.dgvCbxPreEducationRequired.Visible = DgvCbxPreEducationRequiredVisable;
this.dgvTxtPreTargetMonth.Visible = DgvTxtPreTargetMonthVisable;
this.dgvCbxPreEdgeDatesDate.Visible = DgvCbxPreEdgeDatesDateVisable;
this.dgvTxtPreStartDate.Visible = DgvTxtPreStartDateVisable;
this.dgvTxtPreUserName.Visible = DgvTxtPreUserNameVisable;
this.dgvCbxPreProductionId.Visible = DgvCbxPreProductionIdVisable;
return new System.Windows.Forms.DataGridViewColumn[] {
this.dgvTxtPreAccount,
this.dgvTxtPreImpromedAccNum,
this.dgvTxtPreCreateDate,
this.dgvTxtPreCurrentSoftware,
this.dgvTxtPreConversionRequired,
this.dgvTxtPreConversionLevel,
this.dgvTxtPreProgrammer,
this.dgvCbxPreEdge,
this.dgvCbxPreEducationRequired,
this.dgvTxtPreTargetMonth,
this.dgvCbxPreEdgeDatesDate,
this.dgvTxtPreStartDate,
this.dgvTxtPreUserName,
this.dgvCbxPreProductionId,
this.dgvTxtCmnHold,
this.dgvTxtCmnConcern,
this.dgvTxtCmnAccuracyStatus,
this.dgvTxtCmnEconomicStatus,
this.dgvTxtCmnSoftwareStatus,
this.dgvTxtCmnServiceStatus,
this.dgvTxtCmnHardwareStatus,
this.dgvTxtCmnAncillaryStatus,
this.dgvTxtCmnFlowStatus,
this.dgvTxtCmnImpromedAccountNum,
this.dgvTxtCmnOpportunityId};
}
public DataGridViewColumn[] GetProductionColumns()
{
this.dgvcTxtProAccount.Visible = DgvTxtProAccountVisable;
this.dgvTxtProImpromedAccNum.Visible = DgvTxtProImpromedAccNumVisable;
this.dgvTxtProCreateDate.Visible = DgvTxtProCreateDateVisable;
this.dgvTxtProConvRequired.Visible = DgvTxtProConvRequiredVisable;
this.dgvTxtProEdgeRequired.Visible = DgvTxtProEdgeRequiredVisable;
this.dgvTxtProStartDate.Visible = DgvTxtProStartDateVisable;
this.dgvTxtProHardwareRequired.Visible = DgvTxtProHardwareReqiredVisable;
this.dgvTxtProStandardDate.Visible = DgvTxtProStandardDateVisable;
this.dgvTxtProSystemScheduleDate.Visible = DgvTxtProSystemScheduleDateVisable;
this.dgvTxtProHwSystemCompleteDate.Visible = DgvTxtProHwSystemCompleteDateVisable;
this.dgvTxtProHardwareTechnician.Visible = DgvTxtProHardwareTechnicianVisable;
return new System.Windows.Forms.DataGridViewColumn[] {
this.dgvcTxtProAccount,
this.dgvTxtProImpromedAccNum,
this.dgvTxtProCreateDate,
this.dgvTxtProConvRequired,
this.dgvTxtProEdgeRequired,
this.dgvTxtProStartDate,
this.dgvTxtProHardwareRequired,
this.dgvTxtProStandardDate,
this.dgvTxtProSystemScheduleDate,
this.dgvTxtProHwSystemCompleteDate,
this.dgvTxtProHardwareTechnician,
this.dgvTxtCmnHold,
this.dgvTxtCmnConcern,
this.dgvTxtCmnAccuracyStatus,
this.dgvTxtCmnEconomicStatus,
this.dgvTxtCmnSoftwareStatus,
this.dgvTxtCmnServiceStatus,
this.dgvTxtCmnHardwareStatus,
this.dgvTxtCmnAncillaryStatus,
this.dgvTxtCmnFlowStatus,
this.dgvTxtCmnImpromedAccountNum,
this.dgvTxtCmnOpportunityId};
}
public DataGridViewColumn[] GetContractsColumns()
{
this.dgvTxtConAccount.Visible = this.DgvTxtConAccountVisable;
this.dgvTxtConAccuracyStatus.Visible = this.DgvTxtConAccuracyStatusVisable;
this.dgvTxtConCreateDate.Visible = this.DgvTxtConCreateDateVisable;
this.dgvTxtConEconomicStatus.Visible = this.DgvTxtConEconomicStatusVisable;
this.dgvTxtConHardwareStatus.Visible = this.DgvTxtConHardwareStatusVisable;
this.dgvTxtConImpromedAccNum.Visible = this.DgvTxtConImpromedAccNumVisable;
this.dgvTxtConServiceStatus.Visible = this.DgvTxtConServiceStatusVisable;
this.dgvTxtConSoftwareStatus.Visible = this.DgvTxtConSoftwareStatusVisable;
this.dgvCbxConPreProductionId.Visible = this.DgvCbxConPreProductionIdVisable;
this.dgvCbxConProductionId.Visible = this.DgvCbxConProductionVisable;
return new System.Windows.Forms.DataGridViewColumn[] {
this.dgvTxtConAccount,
this.dgvTxtConImpromedAccNum,
this.dgvTxtConCreateDate,
this.dgvTxtConAccuracyStatus,
this.dgvTxtConEconomicStatus,
this.dgvTxtConSoftwareStatus,
this.dgvTxtConServiceStatus,
this.dgvTxtConHardwareStatus,
this.dgvCbxConPreProductionId,
this.dgvCbxConProductionId,
this.dgvTxtCmnHold,
this.dgvTxtCmnConcern,
this.dgvTxtCmnAccuracyStatus,
this.dgvTxtCmnEconomicStatus,
this.dgvTxtCmnSoftwareStatus,
this.dgvTxtCmnServiceStatus,
this.dgvTxtCmnHardwareStatus,
this.dgvTxtCmnAncillaryStatus,
this.dgvTxtCmnFlowStatus,
this.dgvTxtCmnImpromedAccountNum,
this.dgvTxtCmnOpportunityId};
}
The issue is when I check a button the first time, everything shows up ok. I choose another view, everything is ok. But when I click on the first view the columns are out of order (it is like they are in reverse order but it is not exactly the same). this happens only to the first page you click on, the other two are fine. You can click off and click back on as many times as you want after those initial steps, The first list you selected at the start will be out of order the other two will be correct.
Any ideas on what could be causing this?
EDIT--
Things I have found so far:
ColumnDisplayIndexChanged fires many many times (over 200 times) when I view the first selection a second time. if the function does nothing it still loads the page, if i put a dialog box to show it fired (it was a lot of clicks) eventually i either get a big red X in the data grid view area or it loads fine (depending on the page, I get a X for pre-production but the other two loads fine (the message box still shows up hundreds of times) when you select them first)
My best guess is that this.XXX.Fill is changing the DisplayIndex value if the change is occuring after the column range creation function has returned. There are a few things you could consider however.
Create the range of columns once rather than each time a different view is selected.
Is memory an issue? If the datasets are not large and should not be large in the future you could fill 3 seperate containers and change the binding to a different container rather than refilling a single container everytime.
I think I would at the very least create the column ranges only once rather than each time.
Edit
private DataGridViewColumns[] PreProducitonColumns {get;set;}
private DataGridViewColumns[] ProductionColumns {get;set;}
private DataGridViewColumns[] ContractsColumns {get;set;}
private void Form_Load()
{
this.PreProducitonColumns = searchSettings.GetPreProductionColumns();
this.ProductionColumns = searchSettings.GetProductionColumns();
this.ContractsColumns = searchSettings.GetContractsColumns();
}
private void rbContracts_CheckedChanged(object sender, EventArgs e)
{
dgvContracts.Columns.Clear();
if (((RadioButton)sender).Checked == true)
{
if (sender == rbPreProduction)
{
dgvContracts.Columns.AddRange(PreProducitonColumns);
this.contractsBindingSource.DataMember = "Preproduction";
this.preproductionTableAdapter.Fill(this.searchDialogDataSet.Preproduction);
}
else if (sender == rbProduction)
{
dgvContracts.Columns.AddRange(ProductionColumns);
this.contractsBindingSource.DataMember = "Production";
this.productionTableAdapter.Fill(this.searchDialogDataSet.Production);
}
else if (sender == rbContracts)
{
dgvContracts.Columns.AddRange(ContractsColumns);
this.contractsBindingSource.DataMember = "Contracts";
this.contractsTableAdapter.Fill(this.searchDialogDataSet.Contracts);
}
}
}
I took the easy way out. I just created 3 DataGridView and set them visible based off of the radio button.

Categories

Resources