Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all 2535 articles
Browse latest View live

DataRepeater displays incorrect data for a large number of rows (items)

$
0
0

I have a list of Orders (parent list).
Each Order contains multiple products (child list).
 
(Order ... Product is 1...n relationship)

Here my classes:

        public class Order
        {
            public Order()
            {
            }
            public int orderId { get; set; }
            public string customerName { get; set; }
            public string customerEmail { get; set; }
            public virtual ICollection<Item> items { get; set; }
        }
        public class Item
        {
            public Item()
            {
            }
            public string itemId { get; set; }
            public string itemName { get; set; }
            public int itemPrice { get; set; }
            public virtual Order order { get; set; }
        }
        public class CompanyContext : DbContext
        {
            public CompanyContext(): base()
            {

            }
            public DbSet<Order> Order { get; set; }
            public DbSet<Item> Item { get; set; }
        }

OnLoad I use dataRepeater to display all orders. For each datarepeater row, I manually load all the products in a richTextBox1, which is placed inside of each datarepeater row:

        protected override void OnLoad(EventArgs e)
        {
            Program.CompanyContext _context = new Program.CompanyContext();
            List<list_inside_list.Program.Order> listOrders = _context.Order.ToList();
            program_OrderBindingSource1.DataSource = listOrders;

            List<list_inside_list.Program.Item> listItems = _context.Item.ToList();

            DataRepeaterItem currItem = new DataRepeaterItem();
            for (int j = 0; j < this.dataRepeater1.ItemCount; j++)
            {
                this.dataRepeater1.CurrentItemIndex = j;

                var currentOrder = (list_inside_list.Program.Order)program_OrderBindingSource1.Current;
                foreach (var item in currentOrder.items)
                {
                    dataRepeater1.CurrentItem.Controls["richTextBox1"].Text
                        = dataRepeater1.CurrentItem.Controls["richTextBox1"].Text + item.itemName + "\n";
                }
            }
        }
Problem:
For a large quantity of data, and when having gone through the first datarepeater rows (scrolling or arrow-up or -down), richTextBox1 for each row starts to display incorrect data. It only shows some data of the richTextBoxes that were lastly shown.

My Troubleshooting:
1. Repopulating each richTextBox1 through CurrentItemIndexChanged does not solve the problem. It still displays data of the richTextBoxes that were lastly shown.

2. Even using CurrentItemIndexChanged without OnLoading (for example button1 click) and filling each richTextBox1, the first 5 or so richTextBox1 are correctly filled with data, but any later richTextBox1 again starts to show incorrect data (data of the first 5 or so richTextBox1).

3. When using CurrentItemIndexChanged and a new richTextBox2, which is placed outside of the datarepeater, correct data is shown.

Anyone knows how to help? My goal is to display the foreign key child list (in my case "Item.itemName") for every parent (in my case "Order") inside of each datarepeater row, prefereably OnLoad.

Best regards,
philipp-fx 


 

 







Format of Chart Annotation AnchorDataPointName Property String

$
0
0

I've just started to use the Chart control and am quite delighted to find it.  I have posted a separate forums question to help me get around an error while trying to run the C# Chart Samples that I found.  But in the meantime, I'm experimenting myself without any samples.  I'm hoping this is the right forum for Chart questions.

The lack of  sample code in the documentation of the Chart control is a challenge in general.  But I can't find any documentation on the format of the string that's assigned to the Chart.Annotation.AnchorDataPointName property.  I've looked at the designer generated code in a sample I created myself and the string has the format "series name\\r0".  It looks like the "\\r0" designates the index of the data point you want to annotate within the series, but it makes me wonder if there aren't some other formatting goodies the string allows.

So, is there more to the format of the AnchorDataPointName string and am I properly interpreting what I'm seeing?

Thanks.  Steve

 

Sample Code: DataGridView progress bar column

$
0
0

I have a column that has integer data in it, I want to display it as a progress bar in the column so the user can quickly identify lagging processes.

 

I just started with 2005 and it looks great but does anyone know a quick way to do this?

I would also like to change the color of the progress bar based on the cells value.

I found in the data sources toolbox where I can change the column to progress bar but that does not pass through to the grid.

 

Thanks for ANY help with this

Using SQLite Gives Me This Error

$
0
0

Hi I am using SQLite in a project of mine but it gives me the following error "... is a method but is used like a type, this is the code that I have.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Data.SQLite;

namespace TimeZoneDesktopApp
{
    public partial class FormNewImportTextFile : Form
    {
        public FormNewImportTextFile()
        {
            InitializeComponent();
            comboBoxImportData.SelectedIndex = 0;
        }

        private void btnImportSetsBrowse_Click(object sender, EventArgs e)
        {

//function body

        }

        SQLiteConnection sqlc = new SQLiteConnection.CreateFile("database1"); //*** The error occurs on this line

    }
}


How To Border or Otherwise Hightlight a Chart Control StackedColumn

$
0
0

I'd like to put a border around the most recent column the user click in a StackedColumn Chart.  I'm seeing how to put borders around the individual data points in each series displayed in the column, but not around the column as a whole (hopefully including the empty space above and below the data points and without the horizontal lines that appear when I border the series data points).  Is it possible to do what I want and, if so, how?

Thanks.  Steve

P.S.  Instead of bordering the column, it would perhaps be better to have the clicked column widened versus the other columns to make it stand out, or perhaps have a different backcolor.  I'm not seeing a way to do that either.

 

how to bind grid view in C#

$
0
0

i have gridview and i want bind it from data base but it not bind some Cells. it's class of table:

    [Key]
    [Required]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [Column("FldKeyId")]
    public int MyKeyId { get; set; }
    [Required]
    public Machine Machine { get; set; }
    [Required]
    public Employee Employee { get; set; }
    [Required]
    public Shift Shift { get; set; }
    [Required]
    [Column ("FldStartTime")]
    public DateTime MyStartTime { get; set; }
    [Required]
    [Column ("FldEndTime")]
    public DateTime MyEndTime { get; set; }
    [Column("FldModificationDate")]
    [Required]
    public DateTime ModificationDate { get; set; }

that's my code for bind

void RefreshBreakGrid()
    {
        dgvcolDate.DataPropertyName = "ModificationDate";
        dgvcolstarttime.DataPropertyName = "MyStartTime";
        dgvcolendtime.DataPropertyName = "MyEndTime";

        dgvcolemployee.DataSource = Employee.GetAllEmployee();
        dgvcolemployee.DisplayMember = "MyName";
        dgvcolemployee.ValueMember = "MyKeyId";
        dgvcolemployee.DataPropertyName = "Employee";


        dgvcolmachine.DataSource = Machine.GetAllMachine();
        dgvcolmachine.DisplayMember = "MyName";
        dgvcolmachine.ValueMember = "MyKeyId";
        dgvcolmachine.DataPropertyName = "MyName";

        dgvcolshift.DataSource = Shift.GetAllShift();
        dgvcolshift.DisplayMember = "MyName";
        dgvcolshift.ValueMember = "MyKeyId";
        dgvcolshift.DataPropertyName = "Shift";

        _Breaks=Break.GetAllBreak();
        dgvBreak.AutoGenerateColumns = false;
        dgvBreak.DataSource = _Breaks;
    }

that's code for getAllBreaks

public static List<Break> GetAllBreak()
    {
        return new ContexManager().Breaks.Where(c => c.MyKeyId != 0).Include(c => c.Machine).Include(c => c.Employee).Include(c => c.Shift).ToList();
    }

now when it runned in cells of shift it shown classLibrary.classes.shift for machine , employee such as shift what i have to do for it ?



SQLite Really Slow, Any Solutions?

$
0
0

Hi,

So I am importing the lines of a text file, editing the data a little and the inserting into a list in windows forms, thereafter I am writing the contents of this list to a local SQLite table but it is extremely slow - heres my code

 SQLiteCommand insertTimesIntoTable = new SQLiteCommand("insert into tablePeopleTimes (firstname, lastname, empNo, tag, tlName, eName, clock, iOrO, terminalSN, terminalAdd) values (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9)", sqlCon);

                for (int t = personTime.Count - 100; t < personTime.Count; t++)
                {
                    string[] splitCurrent = personTime[t].Split(',');

                    insertTimesIntoTable.Parameters.Add(new SQLiteParameter("@p0", splitCurrent[0]));
                    insertTimesIntoTable.Parameters.Add(new SQLiteParameter("@p1", splitCurrent[1]));
                    insertTimesIntoTable.Parameters.Add(new SQLiteParameter("@p2", splitCurrent[2]));
                    insertTimesIntoTable.Parameters.Add(new SQLiteParameter("@p3", splitCurrent[3]));
                    insertTimesIntoTable.Parameters.Add(new SQLiteParameter("@p4", splitCurrent[4]));
                    insertTimesIntoTable.Parameters.Add(new SQLiteParameter("@p5", splitCurrent[5]));
                    insertTimesIntoTable.Parameters.Add(new SQLiteParameter("@p6", splitCurrent[6]));
                    insertTimesIntoTable.Parameters.Add(new SQLiteParameter("@p7", splitCurrent[7]));
                    insertTimesIntoTable.Parameters.Add(new SQLiteParameter("@p8", splitCurrent[8]));
                    insertTimesIntoTable.Parameters.Add(new SQLiteParameter("@p9", splitCurrent[9]));

                    try
                    {
                        insertTimesIntoTable.ExecuteNonQuery();
                        //insertTimesIntoTable.ExecuteNonQueryAsync();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }

As you can see I have the prepared statement outside the for loop and have limited the writes to the last 100 items in the list but even this is extremely slow - any suggestions on how I could improve this?

                

vs 2003 windows form DataGrid (not DataGridView) fullrow question

$
0
0

Hi,

The vs 2003 C# window form DataGrid.
In the program, how do I know it's full row selected, or just a cell is selected?
Thanks for help.

Jason


I need a local database solution for my winforms app how about SQL Compact Edition

$
0
0
So like the title says but the local database solution would need to ship with the application and not require a separate installation. I have tried SQLite but it is very slow, what do you guys think about SQL Compact Edition?

How Do I Populate A Datagrid Using SQL CE

$
0
0

Hi,

I have successfully managed to import all the lines from a text file. amend the data a little bit, and then write to a local database using SQL Compact Edition. Now how do I go about populating a datagrid on my form with data from the table - details please.

Sort A List not using Lambda

$
0
0

Hi,

I have a string list and wish to sort it without using a lambda expression, I have searched google but the only thing I could find is sorting the list using a lambda expression and since I am not using entity framework in my app I need a way to sort it without using linq - please assist.

c# - how to fix error 'mysys' does not contain a definition for 'DataSet1'

$
0
0

How can I fix this error? It still shows even though I have already created the DataSet1 that the error says that is missing. Help please.

how to bind a gridview to a table has a foreign key

$
0
0

i have table that has 3 foregin key now i want show that in a gridview, the class of table

    [Key]
    [Required]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [Column("FldKeyId")]
    public int MyKeyId { get; set; }
    [Required]
    public virtual Machine Machine { get; set; }
    [Required]
    public virtual Employee Employee { get; set; }
    [Required]
    public virtual Shift Shift { get; set; }
    [Required]
    [Column ("FldStartTime")]
    public DateTime MyStartTime { get; set; }
    [Required]
    [Column ("FldEndTime")]
    public DateTime MyEndTime { get; set; }
    [Column("FldModificationDate")]
    [Required]
    public DateTime ModificationDate { get; set; }

and that is the code for bind to grid view

void RefreshBreakGrid()
    {
        dgvcolDate.DataPropertyName = "ModificationDate";
        dgvcolstarttime.DataPropertyName = "MyStartTime";
        dgvcolendtime.DataPropertyName = "MyEndTime";

        dgvcolemployee.DataSource =    Employee.GetAllEmployee();
        dgvcolemployee.DisplayMember = "MyName";
        dgvcolemployee.ValueMember = "MyKeyId";
        dgvcolemployee.DataPropertyName = "Employee";


        dgvcolmachine.DataSource = Machine.GetAllMachine();
        dgvcolmachine.DisplayMember = "MyName";
        dgvcolmachine.ValueMember = "MyKeyId";
        dgvcolmachine.DataPropertyName = "Machine";

        dgvcolshift.DataSource = Shift.GetAllShift();
        dgvcolshift.DisplayMember = "MyName";
        dgvcolshift.ValueMember = "MyKeyId";
        dgvcolshift.DataPropertyName = "Shift";

        _Breaks=Break.GetAllBreak();
        dgvBreak.AutoGenerateColumns = false;
        dgvBreak.DataSource = _Breaks;
    }

for example methode of getall company:

public static List<Break> GetAllBreak()
{
    return new ContexManager().Breaks.Where(c => c.MyKeyId != 0).Include(c => c.Machine).Include(c => c.Employee).Include(c => c.Shift).ToList();
}

and when i run this code gridview shown classLibrary.classes.shift fro shift field what i have to do show the currect value in gridview. i have use winforms and codeFirst entity framework



Working with data tables

$
0
0

I am working on windows application using C#.net,

I have one data table which will contained multiple result set one by one via loop, and at last i have to merge all result set and display in grid, I am not able to store data table value anywhere so that for next result set data table is empty for  use.

Kindly help me out.

Regard's

Manjeet

Manjeet_24@live.com

SQL Server

$
0
0
I'm trying to find the New Data Source to SQL Server, did I come to the right place? (DNS)

Updating drag-and-drop created DataGridView - how?

$
0
0

I cannot easily modify the layout of a DataGridView created by dragging a data source (SQL Server table) to a Windows form of a desktop app. I would have expected the following to work:

1. Create Data Source and select a complete table from a DB (works just fine)
2. Drag it into a Windows form to create the DataGridView (works just fine including updating data etc)
3. Use the "Configure Data Source with Wizard" to deselect one column of the table
4. In the Form.cs[Design] window the table looks as expected, i.e. the deselected column has disappeared.
5. When I run the desktop app all the original columns are displayed except that the deselected column is now empty of data. I have to delete the DataGridView and drag the data source to the form again to make it work as expected.
6. Now, however, if I add the column again in the Wizard, the re-added column will not re-appear, no matter what I try.

Removing/adding columns via the wizard is only the simplest form modification I will need to do. I will also want to modify the underlying SQL schema, e.g. reorder and remove columns, change the data type of a column. I'd be happy to delete the data source (by either deleting or excluding the DataSet.xsd file) and then adding the data source again. But that does not seem to work without significant manual clean-up of various files. And as I don't understand all the details such a clean-up easily could damage other parts of the app.

My workaround consists in making the mods in the database, creating a new project and recreate the data sources, and then copy and paste my own code from the old to the new project, not something feasible when the project keeps growing. And I was unable to find anything helpful on the net

Any help/pointers are highly appreciated - thanks!

How to Force a Cell into Edit Mode in a DataGridView

$
0
0
Any ideas on how to programmatically force a cell into Edit Mode in a DataGridView?
Background: I have an ImageColumn which allows user to popup a list of 'favourite items' and select one. On selection i am populating another cell with the chosen value, and would like to automatically put that cell in edit mode. (I am not using a ComboBoxColumn because they can edit the value in the column to any value they like).
Also, I know the row and column index of the cell i want to put in edit mode.

Sending datatable for crystal report viewer

$
0
0

Hİ guys :)))

I'm beginner with this coding. I have a problem ..

I'm working on a crystal report viewing.

I have a query for filling data from sql server.

I filled the datatable and I can create the report on same windows form.

I want this. When I clicked the button, the form will sent the datatable and new form will open and report viewer which settled the form will opening with my data's from coming sql server with query at other form..

Yes I know it's hard to understanding. I'm Turkish... :))

Thenk you.. 

how can I design or draw the header of winforms dataGridView as below

$
0
0

combine the first three column to one and text animal, then also text "dog" "cat" "bird" in the three columns below the "animal " column, I want to know how to combine and design the header in datagridview like that.

thanks

DataGridView scrolling and painting without RowHeaders

$
0
0

Dear Sir,

I have issue with row painting when horizontal scrolling in my project. 

And I can reproduce with very simple sample.

DataGridView's setting:

- All borders is single.

- No visualstyles

- No RowHeaders

- FullRowSelect

Scroll and change the row selecting, the row painting is not corrected at the left edge. 

Is this a DataGridView's bug? How do I fix or work around?

Sorry, I can't attached screen shot here.

Thank you.

Tuan Ha

Viewing all 2535 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>