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

Passing data from one form's grid view to another forms text box

$
0
0
Hello expert,
Good day. I m designing a windows application with c# and sqlserver . In this application I need to pass data from One forms grid view to another form text box by applying dialogue box process.
can anybody help me?????????

thanks in advance

Filter Datagridview Without Datasource having 1 lackh rows

$
0
0

Hello,

I am having datagridview with one string column and around 1 lackh rows where Datasource is null, I want to filter datagridview based on textbox text change event but it is taking time to filter and my form turns into not responding state.

string Temp = textBox2.Text.Trim();
            if (Temp != string.Empty)
            {
                this.dataGridView1.Rows.OfType<DataGridViewRow>().Where(r => !r.Cells[0].Value.ToString().ToUpper().Contains(Temp) && !r.Cells[0].Value.ToString().ToLower().Contains(Temp)).ToList().ForEach(row => { if (!row.IsNewRow) row.Visible = false; });
            }
            else
            {
                this.dataGridView1.Rows.OfType<DataGridViewRow>().ToList().ForEach(row => { if (!row.IsNewRow) row.Visible = true; });
            }

WebBrowser control and HttpRequest

$
0
0

Hi,

I am trying to automate a file download from one of the applications (it's an Java application).I am able to reach till download link using web-browser control. Since the downlaod link opens up a "Save file dialog" , my automation does not work fully.So to overcome this I use httprequest/webclient from the URL generated from webbrowser control.However in the Httprequest.getresponse, I never get the attachment file - I get an html saying "system error".

My tries:

I have tried every possible solution, by sending all headers - I see the exact request being created from IE browser vs my Webbrowser control (confirmed using Fiddler).Only difference is the content-length, but I am not able to understand why this difference - what exactly is being missed in the Request header.

Any help/pointers on this would be useful.

C# Winform import Excel file to datagridview

$
0
0

I'm looking for a simple Excel program to import Excel Using OleDb or other. The code I have below is getting an error.

Object reference not set to an instance of an object. Any examples would be appreciated thanks.

using Excel;
using System;
using System.Data;
using System.IO;
using System.Windows.Forms;

namespace Linear_Feet
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        DataSet result;

        private void btnOpen_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "Excel WorkBook 97-2003|*.xls|Excel WorkBook|*.xlsx", ValidateNames = true })
            {
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    FileStream fs = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read);
                    IExcelDataReader reader;
                    if (ofd.FilterIndex == 1)
                    reader = ExcelReaderFactory.CreateBinaryReader(fs);
                    else
                    reader = ExcelReaderFactory.CreateBinaryReader(fs);
                    reader.IsFirstRowAsColumnNames = true;
                    result = reader.AsDataSet();
                    cboSheet.Items.Clear();
                    foreach (DataTable dt in result.Tables)
                        cboSheet.Items.Add(dt.TableName);
                    reader.Close();
                }
            }
        }

        private void cboSheet_SelectedIndexChanged(object sender, EventArgs e)
        {
            dataGridView.DataSource = result.Tables[cboSheet.SelectedIndex];
        }
    }
}
  

 


Booney440

checkbox not working the way I want

$
0
0

HI

I added a checkbox to my form that toggles between the form staying at topmost or not.

Problem is it doesn't deactivate when I uncheck the checkbox?

 private void OnTopbox_CheckedChanged(object sender, EventArgs e)
        {
            if (OnTopbox.Checked)
            {
                this.TopMost = true;
            }

How to turn off "AutoGenerate" of columns when a DataGridView is data-bound

$
0
0

I have a Windows form that has a DataGridView on it.  I have bound the DataGridView to show data, that I specifed,  from the database (I defined the cells that I want to see through the property page).  But, the DataGridView is showing the cells I defined AND the data being returned from the dataset.

So, the question - what property do I set to turn off the default columns being returned from the dataset?  With a web app, there is an "AutoGenerate Columns" that you set to true or false.  What's the WinForm equivalent?

Thanks,

Dexter
 

c# Winform DataGrid copy to end Column

$
0
0

I have a Datagrid with formulas, I want the formula to go to the end of the column. Currently it does the first cell of each column.

 private void button2_Click(object sender, EventArgs e)
        {


            //Part Gross ULD =(H2*I2)/L2

            int H = Convert.ToInt32(dataGridView1.CurrentRow.Cells[7].Value);
            var I = Convert.ToDecimal(dataGridView1.CurrentRow.Cells[8].Value);
            int L = Convert.ToInt32(dataGridView1.CurrentRow.Cells[11].Value);
            var J = H * I / L;
            dataGridView1.CurrentRow.Cells[9].Value = J;
                       
            //ULD Stack =rounddown(106/S2,0)
            int S = Convert.ToInt32(dataGridView1.CurrentRow.Cells[18].Value);
            int A = 106 ;
            int T = A / S;
            dataGridView1.CurrentRow.Cells[19].Value = T;

            //Stacks Wide =rounddown(96/R2,0) 
            int R = Convert.ToInt32(dataGridView1.CurrentRow.Cells[17].Value);
            int B = 96;
            int U = B / R;
            dataGridView1.CurrentRow.Cells[20].Value = U;

            //Stacks Day =roundup(J2/T2,0) FIX IT
            int Gross = Convert.ToInt32(dataGridView1.CurrentRow.Cells[9].Value);
            int Stack = Convert.ToInt32(dataGridView1.CurrentRow.Cells[19].Value);
            int V = Stack / Gross;
            dataGridView1.CurrentRow.Cells[21].Value = V;

            //Linear FT Stack =Q2/12
            Decimal Q = Convert.ToInt32(dataGridView1.CurrentRow.Cells[16].Value);
            var C = 12;
            Decimal W = Q / C;
            dataGridView1.CurrentRow.Cells[22].Value = W;

            //Raw Linear Ft Day =(V2*W2)/U2 FIX IT
            int V21 = Convert.ToInt32(dataGridView1.CurrentRow.Cells[21].Value);
            var W22 = Convert.ToDecimal(dataGridView1.CurrentRow.Cells[22].Value);
            int U20 = Convert.ToInt32(dataGridView1.CurrentRow.Cells[20].Value);
            var X = V21 * W22 / U20;
            dataGridView1.CurrentRow.Cells[23].Value = X;


        }
    }
}


Booney440

What is the RGB value of the color blue used to highlight selected items in a WinForms ListView?

$
0
0
What is the RGB value of the color blue used to highlight selected items in a WinForms ListView?  I have seen a few suggestions online but nothing that is the exact color.

Rob E.


unbound datagridview send the data to a sql table

$
0
0

Hi

I have a datagridview filled with excel data, unbound to the table I want the data in. (see previous entry for that code).  Now I have a table with all the fields match integer, float, string.  I would like to put the data into the table called Stats using Linq, but sqlclient okay.  I have been fussing with it.  What ever happened to just dropping excel data into the database table like I did in 2012.  Well help or ideas would be great.

Thanks

JereTheBear

3-tier WinForms C# Datagrid. Having trouble filling the grid with values from different queries.

$
0
0

Hi!

I'm currently trying to fill my datagridview with values from different queries.

I've started to try and add the result from one query to a specific column. Problem is that since i haven't had much focus on datagridviews i'm somewhat lost i've tried looking up different ways to add values to rows, only that most post or guides want to use SqlClient with the classic "Sqlconnect con= new SqlConnect();"

and bind the data with a different approach than what i'm using.

I'm focusing on getting 1 query added to the datagridview to the correct column before i start making the rest, since i believe getting one to work may be a learning experience that can be applied to the other queries.

This how the presentation layer looks like right now:

//the code in presentation layer

            BusinessManager bm = new BusinessManager();
            
            int agentId = int.Parse(cbAgent.Text.Trim());
            int year = int.Parse(Year.Text.Trim());
            int month = int.Parse(Month.Text.Trim());
            var dtYear = new DateTime(year, 1, 1);
            var dtMonth = new DateTime(1, month, 1);
            
            bm.ChildInsurance(agentId, dtYear, dtMonth);

In the datagridview I have a column named Child Insurrance which I want the result from the query to be added.

in business layer it looks like this:

        public int ChildInsurrance(int agentId, DateTime year, DateTime month)
        {
           int sum = dm.ChildInsurranceSum(agentId, year, month);
            return sum;
        }


And this is the query in data access layer which i will modify, right now i'm just want the value sent and presented in the datagrid:

        public int ChildInsurranceSum (int agentId, DateTime year, DateTime month)
        {
            DataModelContainer db = new DataModelContainer();
            var sum = (from x in db.InsurranceSet
                      join y in db.PrivateApplicationSet on
                      x.Privateapplication.privateApplicationId equals y.privateApplicationId
                      where x.paydate == year & x.paydate == month && y.Agents.agentId == agentId
                      select x).Count();
            return sum;
        }

Any suggestions? Or do you need more info?

Regards 

Gab

NOTE: the variables has been translated to easier to understand.


Student at the University of Borås, Sweden

bound datagridview sbut empty fill with Excel data

$
0
0

Hi

I have a linq context to load an empty table into datagridview1.

I'm trying unsuccessfully to load my excel data into that datagridview.

the excel comes over to the a unbound table but not this bound one.

Help anyone

using System;
using System.Data;
using System.Linq;
using System.Windows.Forms;
using System.IO;
using Excel;

namespace linqFoxExcelSql
{
    public partial class Form1 : Form
    {
        // linq Context to Stats table - Stats is empty - want to fill with excel data
        DataClasses1DataContext db = new DataClasses1DataContext();

        public Form1()
        {
            InitializeComponent();
        }
 
        // open excedl and fill result with the data
        DataSet result;
        private void btnOpen_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "Excel Workbook|*.xls", ValidateNames = true })
            {
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    FileStream fs = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read);
                    IExcelDataReader reader = ExcelReaderFactory.CreateBinaryReader(fs);

                    result = reader.AsDataSet();

                    cboSheet.Items.Clear();
                    foreach (System.Data.DataTable dt in result.Tables)
                        cboSheet.Items.Add(dt.TableName);
                    reader.Close();

                }
            }
        }

        // scbosheet changed get the records
        private void cboSheet_SelectedIndexChanged(object sender, EventArgs e)
        {
            dataGridView1.DataSource = result.Tables[cboSheet.SelectedIndex];
        }

        // use linq to attach or empty sql table - i want to fill this with excel data
        private void Form1_Load(object sender, EventArgs e)
        {
            var Answer = from c in db.Stats
                         select c;
            dataGridView1.DataSource = Answer;
        }
    }
}

Thanks

JereTheBear


Decimal charterer too many decimal spaces

$
0
0

I am getting too many decimal spaces, I only want to see 2 decimal spaces, example (0.67) and (0.04)

This is code.

Thank you

//Linear FT Stack =Q2/12
                Decimal Q = Convert.ToInt32(rows.Cells[16].Value ?? 0);
                var C = 12;
                Decimal W = Q / C;
                rows.Cells[22].Value = W;

                              

//Raw Linear Ft Day =(V2*W2)/U2 

                int V21 = Convert.ToInt32(rows.Cells[21].Value ?? 0);
                var W22 = Convert.ToDecimal(rows.Cells[22].Value ?? 0);
                int U20 = Convert.ToInt32(rows.Cells[20].Value ?? 0);
                var X = V21 == 0 ? 0 : V21 * W22 / U20;
                rows.Cells[23].Value = X;


This is my result with above code.


Booney440


How can I save all the data I typed in datagridview to ms access database? Is it even possible? I need help. I'm using visual c# windows forms app

$
0
0
I just want to save all the data I type in datagridview to make it easier for the user. I'm trying to create a scheduler. Please help me, this is a project due next week :(

DataGridViewComboBoxColumn ignores DataSource string array

$
0
0

With VS2012, created DataGridView with six DataGridViewTextBoxColumn, all read only, all work fine.

Added seventh column in VS2012 designer as DataGridViewComboBoxColumn, not read only.

Set DataSource in C# form constructor as follows:

int row = dataGridView_ActiveJob.Rows.Add(view.viewName, view.cameraName, view.imageSize, view.frameRate.ToString(), mainForm.MakeExposureTime(view.exposureTime), "0%");
DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)(dataGridView_ActiveJob.Rows[row].Cells["Rotate"]);
cell.DataSource = new string[] { "0", "90", "180", "270" };

Form displays properly, showing Rotate column as combo box, but first click of combo box has no reaction, second click has drop down of one row blank, none of the four items in the above string array.

What is preventing combo box from dropping and showing the four string array options?

Dropdown/ComboBox Column Header Cell

$
0
0

How do I create a combobox column header cell that will allow the user to choose the name of the column.  I dont want autofilter or I would use the existing code on MSDN. I want a combobox or button like drop down that is exactly like the autofilter column header cell but without any autofilter features.  I want the user to choose the name of the DataGridView column From a list.

Thanks

J


c# winform if datagrid cell equals Bob next datagrid cell returns Male

$
0
0

I hope I can explain this simply, I have  a Datagrid with several columns. I want to write, if this column [2] has Bob in it than column [3] returns Male. The Excel formula would look like this =IF (Y2 = "Bob"),"Male",0), where Y2 is column [2] Bob  and column [3] returned Male.

what is this function called?


Booney440


DataGridView reset column width

$
0
0

Hi all

in a WinForm I have a Datagridview.

The user can change width  for each column

Is there a statment to reset column widths in the way when the form was loaded ?

Replace one character after the cursor position when pressing a number key any of the MaskedTextBox c # winform

$
0
0

Please help me, I'm having problems when using the MaskedTextBoxin winform.
I built a class to format dates,
I want to when I enter a number then will replace some behind the cursor.

When I press a number key, then the key of characters immediately I entered
will replace the available characters cursor character standing in the MaskedTextBox


So I have to do?



Visual Studio 2017 and Mysql Datasource - Unexpected error and Could not retrieve schema information

$
0
0

Hi

I am using Visual Studio 2017 Community with MYSQL. I want to make windows form to update,delete records...etc.

When i use a datagridview and try to add datasource, at the very end it fails with these messages:

1.Some updating commands could not be generated automatically.
 The database returned the following error.
 Unexpected Error.

2.Could not retrieve schema information for the table or view.

I cant get this to work at all.

I have reinstalled my laptop Win10 three times.

I used all latest versions for Visual Studio, Mysql for VisualStudio and connector/net.

Then i used older version of each and still fails on the same spot.

Please help,

C# rounding up or down in

$
0
0

How would I change this to round up or down ?

I have tried everything but the correct one.

Double, convert to double Trypharse

Thanks

 //= AN2 * AO2
                decimal AN2 = Convert.ToDecimal(rows.Cells[39].Value ?? 0);
                decimal AO2 = Convert.ToDecimal(rows.Cells[40].Value ?? 0);
                var AP = AN2 * AO2;
                rows.Cells[41].Value = AP;


Booney440

Viewing all 2535 articles
Browse latest View live


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