Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8457061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:42:39+00:00 2026-06-10T12:42:39+00:00

My problem is that I have datagrid filled in code like : (…) while

  • 0

My problem is that I have datagrid filled in code like :

(...)
                while (rdr.Read())
                {
                    dataGrid1.Items.Add(new Produkt { nazwa = rdr.GetString(rdr.GetOrdinal("nazwa")), cena = rdr.GetString(rdr.GetOrdinal("cena")), kod = rdr.GetString(rdr.GetOrdinal("kod")) });

                }
(...)

but before i’v declared all columns in my datagrid:

    DataGridTextColumn col1 = new DataGridTextColumn();
    DataGridTextColumn col2 = new DataGridTextColumn();
    DataGridTextColumn col3 = new DataGridTextColumn();
    dataGrid1.Columns.Add(col1);
    dataGrid1.Columns.Add(col2);
    dataGrid1.Columns.Add(col3);
    col1.Binding = new Binding("nazwa");
    col2.Binding = new Binding("cena");
    col3.Binding = new Binding("kod");
    col1.Header = "nazwa";
    col2.Header = "cena";
    col3.Header = "kod";

Now i have added filtering by entered text, so i have 3 textBoxes under datagrid (each column) but their width is not like width from columns in datagrid. I have tried somethink like textbox1.width = datagrid.columns[1].width, but that doesnt work.
Anyone know solution for my problem?

Thanks for any answers!

ps. i cannot just like that declare width (f.e. textbox.width = 200)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:42:41+00:00Added an answer on June 10, 2026 at 12:42 pm

    Try something like that:

    XAML file:

    <Window x:Class="GridAutoWidth.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="30" />
            </Grid.RowDefinitions>
            <DataGrid Name="dgProducts" ItemsSource="{Binding Products}" />
    
            <Grid Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="{Binding ElementName=dgProducts, Path=Columns[0].ActualWidth}" />
                    <ColumnDefinition Width="{Binding ElementName=dgProducts, Path=Columns[1].ActualWidth}" />
                    <ColumnDefinition Width="{Binding ElementName=dgProducts, Path=Columns[2].ActualWidth}" />
                </Grid.ColumnDefinitions>            
                <TextBox Grid.Column="0" />
                <TextBox Grid.Column="1" />
                <TextBox Grid.Column="2" />            
            </Grid>
        </Grid>
    </Window>
    

    Code-behind file:

    using System.Windows;
    
    namespace GridAutoWidth
    {    
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
                this.DataContext = new MainViewModel();
            }
        }
    }
    

    MainViewModel:

    using System.Collections.ObjectModel;
    
    namespace GridAutoWidth
    {
        class MainViewModel
        {
            public MainViewModel()
            {
                for (int i = 0; i < 10; i++)
                {
                    Products.Add(new Product 
                    {
                        Name = "Name " + i,
                        Price = (decimal)(18 * (i + 8.4)),
                        Code = "Sample code " + i
                    });
                }
            }
    
            private ObservableCollection<Product> _products = new ObservableCollection<Product>();
    
            public ObservableCollection<Product> Products
            {
                get { return _products; }
                set { _products = value; }
            }
        }
    
        public class Product
        {
            public string Name { get; set; }
            public decimal Price { get; set; }
            public string Code { get; set; }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataGrid and it has a DataGridTextColumn that has items which I
I have a DataGrid that looks like this (slightly simplified here): <asp:DataGrid ID=grdQuotas runat=server
I have a datagrid that displays items with two columns of text row data
While working on my Silverlight4 SketchFlow prototype I have a datagrid that has a
The problem that I have is somehow very specific. I have to implement a
I have a simple problem that I have not been able to find an
We have the problem that we have the open project files in our SVN
I have a problem that I have not faced before: It seems that the
i have bought a template that have built in contact form problem is that
I have been Googling a problem that I have with trying to integrate the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.