Click here to Skip to main content
15,914,013 members
Home / Discussions / C#
   

C#

 
GeneralRe: Help with WMI Connect Remotely Pin
mniceguy819-Oct-19 9:40
mniceguy819-Oct-19 9:40 
QuestionSimple API to record AVI Files Pin
TyrionTheImp9-Oct-19 2:03
TyrionTheImp9-Oct-19 2:03 
AnswerRe: Simple API to record AVI Files Pin
Richard MacCutchan9-Oct-19 2:49
mveRichard MacCutchan9-Oct-19 2:49 
QuestionWhy is the dataGridView1_SortCompare function not working ? Pin
Member 24584678-Oct-19 23:29
Member 24584678-Oct-19 23:29 
QuestionRe: Why is the dataGridView1_SortCompare function not working ? Pin
Richard MacCutchan8-Oct-19 23:37
mveRichard MacCutchan8-Oct-19 23:37 
AnswerRe: Why is the dataGridView1_SortCompare function not working ? Pin
Member 24584679-Oct-19 15:20
Member 24584679-Oct-19 15:20 
GeneralRe: Why is the dataGridView1_SortCompare function not working ? Pin
Richard MacCutchan9-Oct-19 21:38
mveRichard MacCutchan9-Oct-19 21:38 
GeneralRe: Why is the dataGridView1_SortCompare function not working ? Pin
Member 245846710-Oct-19 18:17
Member 245846710-Oct-19 18:17 
I will post code does not work, I will post my code for you to see, what am I wrong with ?
C#
public partial class Form1 : Form
   {
        public Form1()
        {
            InitializeComponent();
            //sort colum header
            this.dataGridView1.VirtualMode = false;
            this.dataGridView1.SortCompare += new System.Windows.Forms.DataGridViewSortCompareEventHandler(this.dataGridView1_SortCompare);

            dataGridView1.DataSource = CreateTable(5);

        }

        private static DataTable CreateTable(int RowCount)
        {
            DataTable tbl = new DataTable();
            tbl.Columns.Add("check1", typeof(bool));
            tbl.Columns.Add("ID", typeof(int));
            tbl.Columns.Add("Name", typeof(string));
            tbl.Columns.Add("Number", typeof(int));
            tbl.Columns.Add("Date", typeof(DateTime));
            tbl.Columns.Add("check2", typeof(bool));
            for (int i = 0; i < RowCount; i++)
                tbl.Rows.Add(new object[] { false, i, String.Format("Name{0}", i), 3 - i, DateTime.Now.AddDays(i), true });
            return tbl;
        }

        private void dataGridView1_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
        {
            // Try to sort based on the cells in the current column.
            e.SortResult = System.String.Compare(
                e.CellValue1.ToString(), e.CellValue2.ToString());

            // If the cells are equal, sort based on the ID column.
            if (e.SortResult == 0 && e.Column.Name != "ID")
            {
                e.SortResult = System.String.Compare(
                    dataGridView1.Rows[e.RowIndex1].Cells["ID"].Value.ToString(),
                    dataGridView1.Rows[e.RowIndex2].Cells["ID"].Value.ToString());
            }
            e.Handled = true;
        }

    }
image file http://www.mediafire.com/view/9ogb4uwvfr2ag3i/dgv2.jpg/file
GeneralRe: Why is the dataGridView1_SortCompare function not working ? Pin
Richard MacCutchan10-Oct-19 22:03
mveRichard MacCutchan10-Oct-19 22:03 
GeneralRe: Why is the dataGridView1_SortCompare function not working ? Pin
Member 245846714-Oct-19 20:52
Member 245846714-Oct-19 20:52 
GeneralRe: Why is the dataGridView1_SortCompare function not working ? Pin
Richard MacCutchan14-Oct-19 22:00
mveRichard MacCutchan14-Oct-19 22:00 
GeneralRe: Why is the dataGridView1_SortCompare function not working ? Pin
Member 245846717-Oct-19 17:21
Member 245846717-Oct-19 17:21 
Questionunexpected behavior of DataContract serializer: C# language issue Pin
BillWoodruff8-Oct-19 8:07
professionalBillWoodruff8-Oct-19 8:07 
AnswerRe: unexpected behavior of DataContract serializer: C# language issue Pin
Eddy Vluggen8-Oct-19 8:52
professionalEddy Vluggen8-Oct-19 8:52 
AnswerRe: unexpected behavior of DataContract serializer: C# language issue Pin
Richard Deeming8-Oct-19 8:59
mveRichard Deeming8-Oct-19 8:59 
GeneralRe: unexpected behavior of DataContract serializer: C# language issue Pin
BillWoodruff8-Oct-19 12:50
professionalBillWoodruff8-Oct-19 12:50 
QuestionHelp to get only IPv4 address Pin
mniceguy818-Oct-19 7:14
mniceguy818-Oct-19 7:14 
AnswerRe: Help to get only IPv4 address Pin
Richard MacCutchan8-Oct-19 8:02
mveRichard MacCutchan8-Oct-19 8:02 
AnswerRe: Help to get only IPv4 address Pin
Richard Deeming8-Oct-19 8:54
mveRichard Deeming8-Oct-19 8:54 
GeneralRe: Help to get only IPv4 address Pin
mniceguy819-Oct-19 3:51
mniceguy819-Oct-19 3:51 
GeneralRe: Help to get only IPv4 address Pin
Richard Deeming9-Oct-19 7:36
mveRichard Deeming9-Oct-19 7:36 
GeneralRe: Help to get only IPv4 address Pin
mniceguy819-Oct-19 7:41
mniceguy819-Oct-19 7:41 
QuestionDoes the Visual studio C#.net have a progressBar and a control line ? Pin
Member 24584676-Oct-19 23:34
Member 24584676-Oct-19 23:34 
AnswerRe: Does the Visual studio C#.net have a progressBar and a control line ? Pin
Afzaal Ahmad Zeeshan6-Oct-19 23:44
professionalAfzaal Ahmad Zeeshan6-Oct-19 23:44 
GeneralRe: Does the Visual studio C#.net have a progressBar and a control line ? Pin
Member 24584677-Oct-19 16:41
Member 24584677-Oct-19 16:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.